Re: How to give selective access to the methods in a class?
toton wrote On 08/09/06 10:24,:
[...]
One more question, slightly out of topic.
ArrayList can reserve memory for certain size. I expect that memory is
to reserve only the reference, not the object itself (unlike C++
containers where u can reserve for the cobect itself).
Correct. Object instances in Java exist "somewhere
else," and the only things the program manipulates directly
are references and primitives.
How much
effective is this in long run? i.e will JIT make the object contains
side by side? or they will be scattered? (boils down to the question,
array holds the object itself or just the reference ? )
The instances exist "somewhere else," and the ArrayList
holds references to them. The instances might be scattered
or might be grouped together; they might even move around to
different memory locations at different times. That's the
JVM's worry, not yours: The reference still leads to the
instance, no matter where it happens to be located.
I have a
circular buffer which adds several objects from one end and removes
from other end through out the program. It is preferable if the
ArrayList holds the object itself.
As you know by now, the ArrayList holds references and
not instances. I don't see why you would prefer things to
be otherwise -- but in any event, they aren't.
--
Eric.Sosman@sun.com