Methods

Resolving embedded method conflicts

If multiple promoted methods have the same name at the shallowest depth, a direct selector is ambiguous. Select the intended embedded field explicitly or define a method on the outer type. Example output: 'left right'.

Formal Syntax & Structure

go syntaxgo
outer.Left.M(); outer.Right.M()

Working Example

Example Snippetgo
package main
import "fmt"
type Left struct{}
func (Left) Label() string { return "left" }
type Right struct{}
func (Right) Label() string { return "right" }
type Outer struct {  Left  Right}
func main() {  o := Outer{}  fmt.Println(o.Left.Label(), o.Right.Label())}
Go Reference