| Author |
basic collection question
|
Brian Smith
Ranch Hand
Joined: May 20, 2005
Posts: 63
|
|
This is just a general question Is this valid? Is the element o in the arrayList also dereferenced when I set o = null? Or is the object copied when added to the list? Thanks
|
 |
Stan James
(instanceof Sidekick)
Ranch Hand
Joined: Jan 29, 2003
Posts: 8791
|
|
The variable o is a reference to an object. The list has another reference to the same object. When you set o to null or let it go out of scope, the list still has its reference, so the object cannot be garbage collected yet. Did that answer the right question? BTW: Does that compile? If not, can you fix it?
|
A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
|
 |
Brian Smith
Ranch Hand
Joined: May 20, 2005
Posts: 63
|
|
I don't know if it compiles, it was just "air code" to convey my question. Yes that answers my question, thanks. I didn't think it through enough before I posted. I was getting confused between setting an object reference to null and setting the value of the object to null. The answer is obvious now, Thanks. -Brian
|
 |
Brian Smith
Ranch Hand
Joined: May 20, 2005
Posts: 63
|
|
Ok this compiles (Java 1.5)
|
 |
Stan James
(instanceof Sidekick)
Ranch Hand
Joined: Jan 29, 2003
Posts: 8791
|
|
Glad you followed it through to compiling. I suspected that your question didn't really require it, but it's cooler this way.
|
 |
 |
|
|
subject: basic collection question
|
|
|