Summary: | [1.5][compiler] Varargs, generics and a 2D array - Eclipse: error, javac: OK | ||
---|---|---|---|
Product: | [Eclipse Project] JDT | Reporter: | Hosam <ha_tech_2004> |
Component: | Core | Assignee: | Philipe Mulet <philippe_mulet> |
Status: | RESOLVED DUPLICATE | QA Contact: | |
Severity: | normal | ||
Priority: | P3 | ||
Version: | 3.1 | ||
Target Milestone: | 3.1 M5 | ||
Hardware: | PC | ||
OS: | Windows XP | ||
Whiteboard: |
Description
Hosam
2004-12-26 13:31:29 EST
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[]> ? |