4 ms·
> Aren't Go structs subtypes of every interface they conform to? No. There's a defined coercion between values and interface types, which is not the same thing
by pcwalton 10y ago
> Aren't Go structs subtypes of every interface they conform to?
No. There's a defined coercion between values and interface types, which is not the same thing as subtyping. This affects the semantics: for example, you can't pass a value of type []MyStruct to a function taking []interface{}.
- catnaroek 10y agoAFAICT, that only means that [] isn't covariant, which is only to be expected, since slices aren't immutable in Go.