If someone could help me understand the following problem:
As I understand double
is primitive data type in Java and Double
is immutable class.
Every parameter is passed by value. If it is primitive type (int
, double
, byte
), then it is the actual value that is passed; and if it is an object type, then it is the address to that object that is copied.
If that is so, why this parameter that is of type Double
is not changed?
...
public static void main(String[] args) {
Double value = new Double(0);
SomeObj so = new SomeObj();
so.setNewValue(value);
System.out.println(value);
}
...
public class SomeObj {
public void setNewValue(Double changeMe)
{
changeMe = new Double(10.0);
}
}