Embedding
summary
Claim: embedding is not inheritance and behaves differently: the spec only allows embedding a named type T or T (T not a pointer), selectors resolve to the shallowest depth, and promotion evicts ambiguous methods so duplicate names are removed from the method set. Practical consequences: slices/arrays as embedded types are syntax errors, embedding interfaces can cause nil panics, JSON tags change marshal shape, and ambiguous embedding breaks interface implementation. Worked example: generated SDK pattern T embeds customT* preserves user code in production. GitHub: stabbycutyou/embeddingtalk.
AI-written summary · about
chapters (11)
- 0:00Intro
- 2:18DEFINING EMBEDDING AND COMPOSITION
- 3:57HOW DOES IT DIFFER FROM CLASSICAL INHERITANCE?
- 7:07WELL. WHAT DOES THE SPEC SAY?
- 9:48POINTER TYPES
- 13:01SELECTORS
- 16:17CREATING AND SETTING
- 21:27EMBEDDING EXPORTED TYPES
- 23:27EMBEDDING INTERFACES IN STRUCTS
- 28:53MARSHALING AND UNMARSHMALINS
- 36:34EXTENDING GENERATED CODE








