49 ms·
Go doesn’t have inheritance. Defining one type in terms of another is not a subclass. It has embedding, which is a close substitute based on composition, but it
by skybrian 5y ago
Go doesn’t have inheritance. Defining one type in terms of another is not a subclass. It has embedding, which is a close substitute based on composition, but it isn’t the same.
See: https://go.dev/doc/faq#inheritance https://go.dev/doc/faq#inheritance and https://go.dev/doc/effective_go#embedding https://go.dev/doc/effective_go#embedding
It’s a little confusing because for primitive operations, it kind of looks like Go has inheritance, but this isn’t true for user-defined methods. (And automatic casting might in some cases compound the confusion.)
- morelisp 5y ago> automatic casting might in some cases compound the confusion. This is why you should always be careful to distinguish conversions (which aren't automatic) from assignment of untyped constants/literals (which does automatically attach the type, but isn't casting).