I have trouble with interfaces in function arguments.
package main
import (
"fmt"
)
type A interface {
New() A
B()
C()
}
type B interface {
New() B
B()
}
type AS struct {}
func (AS) New() A {
return AS{}
}
func (AS) B() {}
func (AS) C() {}
func Hello(b B) {
b.New()
}
func main() {
fmt.Println("Hello, playground")
as := AS{}
a := A(as)
Hello(a)
}
I've got this error:
tmp/sandbox293137995/main.go:35: cannot use a (type A) as type B in argument to Hello:
A does not implement B (wrong type for New method)
have New() A
want New() B
How can I refactor this code, if I want use interface A in function Hello? Thanks!