Example of error @ play.golang.org: http://play.golang.org/p/GRoqRHnTj6
The following code is returning a "prog.go:16: cannot use NewMyGame (type func() MyGame) as type func() Playable in return argument" even though the interface is completely empty. Please find code attached below too, I'm completely stumped unfortunately and any help would be hugely appreciated.
package main
// Define an arbitrary game type
type MyGame struct{}
// Create a constructor function for arbitrary game type
func NewMyGame() MyGame {
return MyGame{}
}
// Define an interface defining game types
type Playable interface{}
// In my app it will return a list of constructors matching interface
func Playables() func() Playable {
return NewMyGame
}
func main() {}
It's exactly as the error says,
cannot use NewMyGame (type func() MyGame) as type func() Playable
A simple fix would be
func Playables() func() Playable {
return func() (Playable) {
return NewMyGame()
}
}