NetBeans Forums

 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister   ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
  

Doing unique referencing in Java.

 
Post new topic   Reply to topic    NetBeans Forums -> NetBeans Users
View previous topic :: View next topic  
Author Message
Zachary1234



Joined: 08 Nov 2008
Posts: 178

PostPosted: Fri Apr 27, 2012 1:41 am    Post subject: Doing unique referencing in Java. Reply with quote

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

PostPosted: Fri Apr 27, 2012 2:45 am    Post subject: Referencing. Reply with quote

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

PostPosted: Sat Apr 28, 2012 6:45 am    Post subject: Reply with quote

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
Display posts from previous:   
Post new topic   Reply to topic    NetBeans Forums -> NetBeans Users All times are GMT
Page 1 of 1

 
Jump to:  
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


Powered by phpBB
By use of this website, you agree to the NetBeans Policies and Terms of Use. © 2012, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo