Java Properties and References -- I'm not getting what I expect -


I'm a little embarrassed to ask because I should know better, but here I have it.

I have an item "pitcher" with an int property of "RunAlvard". I have an object ballter in which there is a property of "responsible pracharak". I have an object team in which the property is "pitcher" Reaches the base:

  batter. Responsible Picture = Team Picture;  

It's all good and good, though, if the runner is on the base, then we make a pitching change, then I set a new pitch in Team.pitcher:

  Team.pitcher = new pitcher ();  

... and of course this batter. The value of the picture varies.

How can I do this in a different way that the Batter.responsiblePitcher property should continue in the Pitcher to go to the base instead of paying attention to that in the Team.pitcher property? Again, I think I should know this already ...

Thank you.

... and of course this batter changes the value of the pitcher.

This is not true. Your problem is elsewhere. Perhaps you are actually changing values ​​like this:

  Team.pitcher.changeSomeProperty (newValue);  

Then it will actually appear in other contexts because it indicates the same example.

Java is a reference by value language. The following example proves this:

import java.util.Arrays; Public Sector Test {Public Stable Zero Main (String ... Args) {String [] String = New String [] {"Foo", "Bar"}; ChangeReference (strings); Println (Arrays.toString (wired)); // still [foo, bar] changeValue (wire); Println (Arrays.toString (wired)); // [foo, foo]} public static zero change reference (string [] strings) {string = new string [] {"foo", "foo"}; } Public static zero change value (string [] strings) {strings [1] = "foo"; }}

Comments