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{}
}
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{}
}
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