Created
June 18, 2022 04:09
-
-
Save meeech/fd7e6e7ffc8b3e554ec899daf20deae4 to your computer and use it in GitHub Desktop.
field_promotion.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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