The Artima Developer Community
Sponsored Link

Java Answers Forum
copy subject

2 replies on 1 page. Most recent reply: Jan 22, 2004 12:22 PM by Jonathon Brozny

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 2 replies on 1 page
black

Posts: 2
Nickname: blackscorp
Registered: Jan, 2004

copy subject Posted: Jan 22, 2004 11:50 AM
Reply to this message Reply
Advertisement
class something {
.
.
void methode1{
Object object=new Object();
.
.
.
callmeth(object);
.
.
}//end of methode1

void callmeth(Object object) {
Object copyObject=new Object();

copyObject=object;
.
.
.
copyObject.variable=12;
.
.
System.out.print(copyObject==object);
}//end of callmeth
}//end of class


why callmethode(...) prints true.I mean why copyObject is the same with object eventhought i changed copyObject.How do i fix this.Sorry for bad grammar...


Jonathon Brozny

Posts: 24
Nickname: jonathon
Registered: Oct, 2003

Re: copy subject Posted: Jan 22, 2004 12:21 PM
Reply to this message Reply
You did make a new object, but then you discarded the new object references and referenced the first object again when you went.
Object copyObject=new Object();

now you just have 2 references to the same object.

Jonathon Brozny

Posts: 24
Nickname: jonathon
Registered: Oct, 2003

Re: copy subject Posted: Jan 22, 2004 12:22 PM
Reply to this message Reply
Right, that was good. that line should have been
copyObject=object;

Flat View: This topic has 2 replies on 1 page
Topic: server side authentication Previous Topic   Next Topic Topic: Populate JTable

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use