I see an interface structure in the golang 1.18 codebase in builtin.go
// comparable is an interface that is implemented by all comparable types
// (booleans, numbers, strings, pointers, channels, arrays of comparable types,
// structs whose fields are all comparable types).
// The comparable interface may only be used as a type parameter constraint,
// not as the type of a variable.
type comparable interface{ comparable }
I can’t understand how this can compile. If I copy this in my main.go the compiler says recursive interface definition.
// That compiles
// But What I can I do with that ?
type myInterface interface{ string }
}
// That compiles too
type MyStruct struct {
A string
B bool
}
type MyStruct2 struct {
B string
C bool
}
type myInterface interface {
MyStruct
MyStruct2
Foo()
}
type MyStruct3 struct {
}
func (o MyStruct3) Foo() {
// So what ca I do with MyStruct and MyStruct2 at this moment ?
}