I come from C++ with pointers and references ( const string& str
/ string* str
).
I learnt that you create an object in Java via the new statement.
Bucket b1 = new Bucket();
So now I have a reference called b1
which "points" to an object of type Bucket
, right?
Well in my android application I handle a lot with lists. These lists might have 1000 objects inside.
for( int i = 0; i < 1000; i++ )
myList.add( new Bucket() );
My list now, contains 1000 Bucket
objects. Or does it contain 1000 references to Bucket
objects?
But if i add another item to the list like this :
b1 = new Bucket();
myList.add( b1 );
do b1
and myList
refer to/ contain the same object (of course, myList
at its last index )?
And if I have another list :
List<Bucket> anotherList = myList;
do both lists refer to or contain the same objects? Or does anotherList
refer to myList
?