wrote:
TheVooDooChild coughed up:
Thank you for the reply, this seems to work fine. Why do you say this
is a destructive operation?
He probably is simply flagging the fact that the array is being altered
in
place irrecoverably.
Yes, because changing a method parameter is a side effect.
Normally, a method doesn't change it's parameters (side effects are
generally more difficult to test). So because
java.util.Arrays#sort(Object[]) does change it's parameter, he flags it.
Doesn't the sort method just change the reference "myArray" to refer to
a new object created by the sort method?
No, and there are two easy ways to see that this is
so. First, observe that the method is `void', meaning
that it returns no value. If it created a new array
behind the scenes somewhere, it would have no way to
return that new array to the caller.
The second way to discover this is even easier and
more straightforward, and requires no heavy thinking:
"When all else fails, read the Javadoc."