Created
February 7, 2017 08:14
-
-
Save asd1245dss/cba6e7b15e64bb18b578858c5cf864c3 to your computer and use it in GitHub Desktop.
Java array clone is not deep clone,so all the elements in the array are same class
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Test | |
public void testArrayClone() { | |
UnsafeSequence[] unsafeSequences = new UnsafeSequence[10]; | |
for (int i = 0; i < unsafeSequences.length; i++) { | |
unsafeSequences[i] = new UnsafeSequence(); | |
} | |
UnsafeSequence[] unsafeSequencesClone = unsafeSequences.clone(); | |
System.out.println(Arrays.toString(unsafeSequences)); | |
System.out.println(Arrays.toString(unsafeSequencesClone)); | |
unsafeSequencesClone[0].getNext(); | |
System.out.println(Arrays.toString(unsafeSequences)); | |
System.out.println(Arrays.toString(unsafeSequencesClone)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment