interfaces
Interfaces
type Animal interface {
Speak() string
}Usage
type Dog struct {
//...
}
func (d Dog) Speak() string {
return "Woof"
}
func main() {
poodle:= Animal(Dog()) //cast as Animal
}The empty interface
Last updated