Skip to content

Instantly share code, notes, and snippets.

@meeech
Created June 18, 2022 04:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save meeech/fd7e6e7ffc8b3e554ec899daf20deae4 to your computer and use it in GitHub Desktop.
Save meeech/fd7e6e7ffc8b3e554ec899daf20deae4 to your computer and use it in GitHub Desktop.
field_promotion.go
package main
import "fmt"
type Original struct {
foo string
bar string
}
func (o *Original) Foo() string {
return o.foo
}
func (o *Original) Bar() string {
return o.bar
}
type Extended struct {
Original
}
func (o *Extended) Bar() string {
return "woot"
}
func main() {
o := Original{foo: "foo", bar: "bar"}
e := Extended{Original: o}
fmt.Printf("%+v\n", o) // {foo:foo bar:bar}
fmt.Printf("%+v\n", e.Bar()) // woot
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment