I want to have something like this:
type MyInterface interface {
MyMetod(interface{})
}
and to have the type
type MyType struct {}
with method
func (mt *MyType) MyMethod(SomeConcreteType) {
// body
}
implementing MyInterface.
But it seems that Go can't handle this. I recieve an error that says that it have MyMethod(SomeConcreteType) but it wants MyMethod(interface{}). Why is this so, and what would be a good solution to this problem?
Why is this? It's the language design.
Solution would be to match the interface:
type MyType struct{}
func (mt *MyType) MyMethod(v interface{}) {
v, ok := v.(SomeConcreteType)
if !ok {
panic("!ok")
}
v.doStuff()
}