Bug 81911 - [1.5][compiler] Varargs, generics and a 2D array - Eclipse: error, javac: OK
Summary: [1.5][compiler] Varargs, generics and a 2D array - Eclipse: error, javac: OK
Status: RESOLVED DUPLICATE of bug 81590
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.1   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: 3.1 M5   Edit
Assignee: Philipe Mulet CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2004-12-26 13:31 EST by Hosam CLA
Modified: 2005-01-14 11:42 EST (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Hosam CLA 2004-12-26 13:31:29 EST
The following code compiles using javac, but not in Eclipse M4:

String[][] arr1;	// initialized here
ArrayList<String[]> arr2 = new ArrayList<String[]>(Arrays.asList(courses));
Comment 1 Olivier Thomann CLA 2004-12-27 11:26:52 EST
Could you please provide a complete test case?
Comment 2 Hosam CLA 2004-12-27 13:49:19 EST
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.
Comment 3 Jerome Lanneluc CLA 2005-01-04 06:46:43 EST
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".
Comment 4 Kent Johnson CLA 2005-01-10 13:46:02 EST
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[]> ?
Comment 5 Philipe Mulet CLA 2005-01-14 11:42:36 EST
Added: VarargsTest#test021

*** This bug has been marked as a duplicate of 81590 ***