Herks
Herks

Reputation: 897

Listing interfaces in interfaces in Go

I don't understand the following code snippet in the container/heap package.

type Interface interface {
    sort.Interface   //Is this line a method?
    Push(x interface{})
    Pop() interface{}
}

Upvotes: 7

Views: 163

Answers (1)

Denys Séguret
Denys Séguret

Reputation: 382264

This is a type declaration.

The heap.Interface interface embeds the sort.Interface interface.

You can see it as a kind of inheritance/specialization : it means that the structs implementing the heap.Interface interface are defined as the ones that implement the sort.Interface methods and the Push and Pop methods.

Interface embeding is described in Effective Go : http://golang.org/doc/effective_go.html#embedding

Upvotes: 7

Related Questions