4 ms·
Normally you wouldn’t contrive to use embedded struct fields in this way. And you can’t have the same kind of composition with methods - it’s a compiler error:
by bilbo-b-baggins 1y ago
Normally you wouldn’t contrive to use embedded struct fields in this way. And you can’t have the same kind of composition with methods - it’s a compiler error:
https://go.dev/play/p/r04tPta1xZo https://go.dev/play/p/r04tPta1xZo
So the whole article is basically about using the language in a way you normally would ever do.
- whatevertrevor 1y agoThis can be simplified, conflicting field names at the same level also don't compile: https://go.dev/play/p/D3eFi9_can8 https://go.dev/play/p/D3eFi9_can8 Conflicting functions at nested levels also compile: https://go.dev/play/p/xXXDZCjQJOh https://go.dev/play/p/xXXDZCjQJOh It's not about method vs field, it's about the nesting level of the conflicting identifier, if it's at the same level there's an error, if it's at different levels, the higher level hides the lower level identifier: https://go.dev/doc/effective_go#embedding https://go.dev/doc/effective_go#embedding