NetBeans Forums
| View previous topic :: View next topic |
| Author |
Message |
Zachary1234
Joined: 08 Nov 2008 Posts: 178
|
Posted: Fri Apr 27, 2012 1:41 am Post subject: Doing unique referencing in Java. |
|
|
I want to set up a situation on an object in java where I have two
variables referring to one object, such that the object is changed,
but that the variables don't need to be mentioned for reassignment again, such that they automatically maintain a reference to an object,
and update behind the scenes automatically.
Can this be done? I'm not quite sure either way. Consider the following:
//***********************************************************
String object = new String("one");
System.out.println(object);
String reference = object;
String a = reference;
System.out.println(a);
String b = reference;
System.out.println(b);
reference = object = new String("two");
System.out.println(a); //Should automatically point to the second object, doesn't.
System.out.println(b);//Should automatically point to the second object, doesn't.
//*********************************************************** |
|
| Back to top |
|
 |
Zachary1234
Joined: 08 Nov 2008 Posts: 178
|
Posted: Fri Apr 27, 2012 2:45 am Post subject: Referencing. |
|
|
This referencing approach will not work on primitive data.
You also need to be careful on the primitive data wrapper classes,
as they have a way of getting converted back to primitives
inside System.out.println(x);, which the supplied example does not quite catch. Apart from that, java handles the process for you. |
|
| Back to top |
|
 |
lanshan75
Joined: 28 Apr 2012 Posts: 3 Location: florida
|
Posted: Sat Apr 28, 2012 6:45 am Post subject: |
|
|
I am totally agree with what you said,but my English is poor, sometiomes I don't know how to express my feeling,I just want to make some friends who can help me in my English and share the happiness with each other.
_____________________________________
Buy WOW Gold|
Buy RS Gold|
Diablo 3 Gold |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You can attach files in this forum You can download files in this forum
|
|