Community
Participate
Working Groups
There seems to be a problem with the compiler (I think) that shows up in the Arrays.toList method. The following program displays the problem: import java.util.*; public class foo { public static void main(String[] args) { double[][] d = { { 1 } , { 2 } }; List l = Arrays.asList(d); System.out.println("List size: " + l.size()); } } In eclipse, I get the output: List size: 1 Using the Java 5 compiler I get the expected: List size: 2 It seems that the Eclipse compiler doesn't recognize a double[][] as an Object[] and so wraps it in a new Object[] containing the double[][]. If I add an explicit cast to Object[] in eclipse I get the expected result: public class foo { public static void main(String[] args) { double[][] d = { { 1 } , { 2 } }; List l = Arrays.asList((Object[]) d); System.out.println("List size: " + l.size()); } } List size: 2
If I change the code to look like this: import java.util.*; public class X { public static void main(String[] args) { double[][] d = { { 1 } , { 2 } }; List<double[]> l = Arrays.asList(d); System.out.println("List size: " + l.size()); } } The problem is more obvious. It doesn't compile and report: ---------- 1. ERROR in d:\tests_sources\X.java (at line 6) List<double[]> l = Arrays.asList(d); ^^^^^^^^^^^^^^^^ Type mismatch: cannot convert from List<double[][]> to List<double[]> ---------- 1 problem (1 error) Arrays.asList(d) is resolved to a binding where the parameter type is double[][][] instead of double[][]. The varargs should "consume" one dimension. If compiled using 1.4 compliance, it works fine.
It seems that it fails only with base type array. The problem might come from the if statement in org.eclipse.jdt.internal.compiler.lookup.ParameterizedGenericMethodBinding line 134.
Problem indeed comes from abusive removal of one vararg type dimension before launching inference. Removal should have only occur for a mono dimensional array type. Fixed both in 3.1.1 and 3.2 stream. Added VarargsTest#test034.
Verified in I20050921-0010 for 3.2M2
Verified using M20050923-1430 for 3.1.1