Struct semantics
Embedded struct fields
An embedded field uses a type name rather than an explicit field name. Its implicit name is the unqualified type name; accessible fields and methods may be promoted. Embedding is composition, not subclass inheritance. Example output: '9 9'.
Formal Syntax & Structure
go syntaxgo
type Outer struct { Inner }Working Example
Example Snippetgo
package main
import "fmt"
type Inner struct{ ID int }type Outer struct{ Inner }
func main() { x := Outer{Inner: Inner{ID: 9}} fmt.Println(x.ID, x.Inner.ID)}