3 ms·
Why do good people downvote what they don't understand? https://play.golang.org/p/d0TkGTCZa2S https://play.golang.org/p/d0TkGTCZa2S Runtime results in panic:
by loopz 7y ago
Why do good people downvote what they don't understand?
https://play.golang.org/p/d0TkGTCZa2S https://play.golang.org/p/d0TkGTCZa2S
Runtime results in panic:
4
Canin
panic: interface conversion: main.Dog is not interface {
Happy() bool }: missing method Happy
goroutine 1 [running]: main.main() /tmp/sandbox251002434/prog.go:18 +0x200
Using interface casting, Golang do support "duck typing" in similar fashion as ruby's Object class.
Here, by convention, the instance of Dog doesn't support "type" Happy(), therefore fails at runtime.
So golang is somewhat dynamic as well, although using interface{} is kludgy and one would want to avoid that and reflection whenever possible.