I'm trying to create a cloneable interface and am running into some problems getting structs to implement the interface. It appears this is a limit of go which isn't in many other langauges. I'm trying to understand the justification for this limit.
var _ Cloneable = test{}
type Cloneable interface {
Clone() Cloneable
}
type test struct {
}
func (t *test) Clone() *test {
c := *t
return &c
}
Playground: https://play.golang.org/p/Kugatx3Zpw
Followup question since it still seems weird to me. This also does not compile
var _ Cloneable = &test{}
type Cloneable interface {
Clone() Cloneable
}
type Cloneable2 interface {
Clone() Cloneable2
}
type test struct {
}
func (t *test) Clone() Cloneable2 {
c := *t
return &c
}
Playground: https://play.golang.org/p/jlyMDPF1WB