package main
import "fmt"
type MyInterface interface {
Build() string
}
type MyImplementingStruct struct{}
func (i MyImplementingStruct) Build() string { return "Hello World!" }
type MyOtherStruct struct {
UsesInterfacePtr *MyInterface
}
func main() {
// Works
var a MyInterface
a = MyImplementingStruct{}
b := MyOtherStruct{
UsesInterfacePtr: &a,
}
// Doesnt work
d := MyImplementingStruct{}
e := MyOtherStruct{
UsesInterfacePtr: &d, // "&d *MyImplementingStruct doesnt implement *MyInterface" ??
}
fmt.Println(b)
fmt.Println(e)
}
Is it necessary to define the type in var? It cant just be inferred?