Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

I know that double behaves differently than Double but I don't yet know all of the details. For example for:

Code Block
titlejava
example.java
protected double[] _refPoint = new double[3];

public void setReferencePoint(double[] point){
   _refPoint = point;
}

...

Wiki Markup
No copy at all, it just changes the {{_refPoint}} variable to reference the passed in array, and presumably eventually garbage collects the old {{double\[3\]}}. This is not in general a good idea, because the code may not behave the way the caller expects, for example:

Code Block
titlejava
example.java
double d = { 1, 2, 3}
setReferencePoint(d);
d[0] = 3;

changes the array which is now referenced internally by the class containing setReferencePoint. It is probably better practice to internally clone the array, for example:

Code Block
titlejava
example.java
public void setReferencePoint(double[] point){
   _refPoint = point.clone();
}

...