Created
October 1, 2012 10:45
-
-
Save robinst/3810891 to your computer and use it in GitHub Desktop.
VarargWithArray dangerous
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
import java.util.Arrays; | |
public class VarargWithArray { | |
public static void main(String[] args) { | |
int[] ints = {1, 2, 3}; | |
MyList l = new MyList(ints); | |
ints[0] = 666; | |
System.out.println(l); | |
} | |
private static class MyList { | |
private int[] elements; | |
public MyList(int... elements) { | |
this.elements = elements; | |
} | |
@Override | |
public String toString() { | |
return Arrays.toString(elements); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment