So we know that Java uses pass by value, i.e. it passes a copy of the reference to the methods.
I am wondering why is it then, that when I test the parameter reference (param in my example) with the original reference (string in my example) is says they are the same?
Shouldn't the following code return false, i.e. the references are not the same, because a copy reference (i.e. a new reference) is passed by value?
public class Interesting {
private String string;
public Interesting(final String interestig) {
super();
string = interestig; // original reference is tested against copy reference and it says they are the same
}
public boolean isItTheSame(final String param) {
return param == string;
}
public static void main(final String args[]) {
Interesting obj = new Interesting("String");
System.out.println(obj.isItTheSame(obj.string)); //copy of reference is created here
}
}