Skip to content

Instantly share code, notes, and snippets.

@robinst
Created October 1, 2012 10:45
Show Gist options
  • Save robinst/3810891 to your computer and use it in GitHub Desktop.
Save robinst/3810891 to your computer and use it in GitHub Desktop.
VarargWithArray dangerous
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