Relative Content

Tag Archive for go

Struct inside the interface

package main import “fmt” type Dog struct { Name string } type Animal interface { Dog Speak() } func (d Dog) Speak() { fmt.Println(“Woof!”) } func main() { d := Dog{Name: “Fido”} fmt.Println(d) d.Speak() } Why does this code block not raise error? Is this valid? If yes, then what are the use cases for […]