This question already has an answer here:
I am trying to understand embedding in Go and this is what I tried to do -
I created a type A
with an exported field X
and have a function Update
on A
update X
with user provided input.
type A struct {
X int
}
func (a A) Update(v int) {
a.X = v
}
The I define two types A1
and A2
and make them update X
with different values. My expectation was that A1
's update will not effect A2
's update. So I did this -
https://play.golang.org/p/Rjh3hyw_nb0
What I get is all 0's in the output.
Firstly - is the expectation correct? Do A1
and A2
have different reference to A.X
Secondly - why does it print all 0's instead of updated value of X?
</div>