As @TimCooper commentator mentioned, if it Vertexwas an interface type, you would have to explicitly specify the specific type that implements the interface, since the compiler could not reasonably guess which implementation you are accessing, for example:
type NoiseMaker interface { MakeNoise() string }
type Person struct {}
func (p Person) MakeNoise() string {
return "Hello!"
}
type Car struct {}
func (c Car) MakeNoise() string {
return "Vroom!"
}
noisemakers := map[string]NoiseMaker{
"alice": Person{},
"honda": Car{},
}
source
share