When copying an entire array, I've often seen people write:
int[] dest = new int[orig.length];
System.arraycopy(orig, 0, dest, 0, orig.length);
But it seems to me there is no reason to favor this over:
int[] dest = orig.clone();
They're both shallow copies anyway. Probably these folks just don't realize that clone
exists. So is there any reason not to use clone
?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…