I am a bit confused about Java's pass by reference/values in method parameters.
I have a constructor in an OuterObject
class:
private InnerObject io;
public OuterObject(InnerObject io){
this.io = io;
}
public InnerObject getInnerObject(){
return this.io;
}
If I pass an OuterObject
into a copy method like this:
InnerObject io = new InnerObject();
OuterObject o = new OuterObject(io);
anotherClass.getCopyOf(o);
and in another class:
public static OuterObject getCopyOf(InnerObject o){
return new OuterObject(o.getInnerObject());
}
As you can see I create the OuterObject
with the InnerObject
as a parameter. Now I would like to know:
Do I get two new Objects from the return statement,
or is it only a new OuterObject
copy but same reference to the existing InnerObject
?