I am confused by how object references work. In the below example, at the end of the loop, Will result point to the myList.get(9) or myList.get(3)?
Class MyClass{
...
}
public static MyClass myUtilityMethod(){
List<MyClass> myList = new ArrayList<MyClass>(10);
//initialize the list
....
////////////
MyClass tmp = null;
MyClass result = null;
for(int i =0; i < 10; i++){
temp = myList.get(i);
if(i == 3) result = temp;
}
return result;
}
Since result points to temp and temp changes in every loop iteration, does it mean that result will also change based on where temp is pointing?