Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migrated to Confluence 4.0

...

Does this do a shallow copy or a deep copy?

Answer

Wiki MarkupNo 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
java
java
double d = { 1, 2, 3}
setReferencePoint(d);
d[0] = 3;

...

or to make sure the documentation to setReferencePoint explains that it will hold a reference to the array and the user should not modify it.

Wiki MarkupIn fact we generally discourage the use of {{double\[3\]}} for momentum or space point. Try using Hep3Vector instead:

http://java.freehep.org/freehep-physics/apidocs/hep/physics/vec/Hep3Vector.htmlImage Removed