Community
Participate
Working Groups
The following code compiles using javac, but not in Eclipse M4: String[][] arr1; // initialized here ArrayList<String[]> arr2 = new ArrayList<String[]>(Arrays.asList(courses));
Could you please provide a complete test case?
I don't understand what exactly you mean by "complete test case", but the bug is simply obvious here: public class Test { public static void main(String[] args) { String[][] arr = new String[][] { args }; ArrayList<String[]> al = new ArrayList<String[]>(Arrays.asList(arr)); } } I think that the problem might be related to sending an array to a varargs method. However, I tried to correct it as such: al = new ArrayList<String[]>(Arrays.asList<String[]>(arr)); This makes an error too. A stranger error occurs when writing: "asList<String>" in the same place.
Complete test case: import java.util.ArrayList; import java.util.Arrays; public class X { public static void main(String[] args) { String[][] arr = new String[][] { args }; ArrayList<String[]> al = new ArrayList<String[]>(Arrays.asList(arr)); } } The error reported is: "The constructor ArrayList<String[]>(List<String[][]>) is undefined".
The problem comes from our substitution of the return type for Arrays.asList: List<T> asList(T[]) is called with (java.lang.String[][]) So why is the return type List<String[][]> and not List<String[]> ?
Added: VarargsTest#test021 *** This bug has been marked as a duplicate of 81590 ***