DateTest test100 = new DateTest("ABC",100);
dateTestMap.put(96, test100);
Here a copy of reference (of test100
) goes and sits into the dateTestMap
which points to DateTest("ABC",100)
. Now a HashMap dateTestMap
contains a new reference which points to the same object DateTest("ABC",100)
So it can be depicted something like this
Now when you do
test100 = datePassingTest(test100);
The outer test100
will point to new DateTest("XYZ", 69)
, but the copy reference present in dateTestMap
still points to same DateTest("ABC",100)
object.
Java is pass by value - which essentially means passing the copy of reference