Java Properties and References -- I'm not getting what I expect.
Posted
by Blumer
on Stack Overflow
See other posts from Stack Overflow
or by Blumer
Published on 2010-05-15T17:29:14Z
Indexed on
2010/05/15
17:34 UTC
Read the original article
Hit count: 302
I'm a little embarrassed to ask this as I ought to know better, but here's what I've got.
I have an object "Pitcher" with an int property of "runsAllowed". I have an object Batter that has a property of "responsiblePitcher". I have an object Team that has a property "pitcher". When the batter reaches base:
Batter.responsiblePitcher = Team.pitcher;
All that's well and good. However, if we have a pitching change while the runner is on base, I set a new pitcher in Team.pitcher:
Team.pitcher = new Pitcher();
... and of course this changes the value of Batter.pitcher.
How should I be doing things differently such that the Batter.responsiblePitcher property continues to point to the pitcher who let him on base instead of pointing at whever is in the Team.pitcher property? Again, I feel like I ought to know this already ...
Thanks.
© Stack Overflow or respective owner