The struct Dog
implemetments all the methods of interface Animal
, why does *Dos
can't be assigned to *Animal
?
type Animal interface {
run()
}
type Dog struct {
name string
}
func (d *Dog) run() {
fmt.Println( d.name , " is running")
}
func main(){
var d *Dog
var a *Animal
d = new(Dog)
d.run()
a = d //errors here
}
Go informs the following errros:
Cannot use 'd' (type *Dog) as type *Animal in assignment