Community
Participate
Working Groups
With compiler compliance leve set to 5.0, in the following junit test case testIteratedAccess fails. import java.util.Arrays; import java.util.Iterator; import junit.framework.TestCase; public class NestedArrayTest extends TestCase { private String[] a1; private String[] a2; private String[][] a; protected void setUp() { a1 = new String[] { "a", "b", "c" }; a2 = new String[] { "x", "y", "z" }; a = new String[][] { a1, a2 }; } public void testArraySize() { assertEquals(2, a.length); } public void testIndexedAccess() { assertEquals(a1, a[0]); assertEquals(a2, a[1]); } public void testIteratedAccess() { Iterator iter = Arrays.asList(a).iterator(); assertTrue(iter.hasNext()); assertEquals(a1, iter.next()); assertTrue(iter.hasNext()); assertEquals(a2, iter.next()); assertFalse(iter.hasNext()); } }
smaller test-case: String[][] x = {{"X"}, {"Y"}}; List l = Arrays.asList(x); System.out.println(l.size() + " " + l.get(0).getClass().getName()); Compliance Level 1.4: 2 [Ljava.lang.String; Compliance Level 5.0: 1 [[Ljava.lang.String;
Problem comes from varargs support which induces one extra array wrappering for 'x' in Arrays.asList(x) invocation.
*** Bug 81911 has been marked as a duplicate of this bug. ***
Tuned method type inference near varargs support. Added VarargsTest#test018-test020. Fixed
I have an existing project that includes code suffering from this bug. Is there a way to make it compile in Eclipse M4? I can't wait for M5.
You could wait for next nightly build, and copy plugin org.eclipse.jdt.core back into a M4 install.
Verified in I20050214