To add to Jon's answer: asList
takes a vararg (variable arity) parameter list, and vararg parameters don't autobox the way one might expect. A simple case that doesn't involve generics:
public void foo(Double... x) { whatever }
double[] doubleArray1 = {1D,2D,3D};
foo(doubleArray1); // error
gives the error argument type double[] does not conform to vararg element type Double
. The same applies to asList
; what happens here is that since Arrays.asList
is generic and you haven't explicitly given it the generic type, it will pick whatever works; Double
doesn't work (for the same reasons the foo
call won't compile), and double[]
does work. This expression, where you explicitly give it the generic parameter, will give you the same error at compile time:
Arrays.<Double>asList(doubleArray1).contains(1D)