Name: rmT116609 Date: 02/11/2004
FULL PRODUCT VERSION :
java version "1.5.0-beta"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0-beta-b32c)
Java HotSpot(TM) Client VM (build 1.5.0-beta-b32c, mixed mode)
ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows XP [Version 5.1.2600]
A DESCRIPTION OF THE PROBLEM :
JDK 1.5 introduces the concept of autoboxing, of automatically converting between primitives and Objects.
As such, passing an int[] into Arrays.asList(Object[]) should automatically convert it into an Integer[], thus allowing the resulting list to be a List<Integer>.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Compile the attached source with "-source 1.5" and any one of the three included examples uncommented.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
I expect to, at the very minimum, have the int[] autoboxed into Integer[] as this is one of the new improvements for JDK 1.5
Preferably, I would also like to have the return results be a List<Integer> as per the Generics changes in 1.5
Please note that someone else requested the same functionality in JDK 1.3 as per Bug #4348595, but it was not to be implemented because it required Autoboxing, which JDK 1.5 is now supposed to have.
ACTUAL -
Error messages included as comments in the attached source
ERROR MESSAGES/STACK TRACES THAT OCCUR :
Error messages included as comments in the attached source
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
import java.util.*;
public class arrayTest
{
public static void main(String[] args)
{
int[] array = new int[]{1,2,3,4,5,6,7,8,9};
/**
* E:\java\examples>javac -source 1.5 arrayTest.java
* arrayTest.java:19: <T>asList(T[]) in java.util.Arrays cannot be applied to (int[
* ]); inferred type argument(s) int do not conform to bounds of type variable(s) T
* List list = Arrays.asList(array);
* ArrayList<Integer> list = new ArrayList<Integer>(array);
* ^
* 1 error
*/
//List list = Arrays.asList(array);
/**
* E:\java\examples>javac -source 1.5 arrayTest.java
* arrayTest.java:30: cannot find symbol
* symbol : constructor ArrayList(int[])
* location: class java.util.ArrayList<java.lang.Integer>
* ArrayList<Integer> list = new ArrayList<Integer>(array);
* ^
* 1 error
*/
//ArrayList<Integer> list = new ArrayList<Integer>(array);
/**
* E:\java\examples>javac -source 1.5 arrayTest.java
* arrayTest.java:42: cannot find symbol
* symbol : method addAll(int[])
* location: class java.util.ArrayList<java.lang.Integer>
* list.addAll(array);
* ^
* 1 error
*/
//ArrayList<Integer> list = new ArrayList<Integer>();
//list.addAll(array);
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
Manually iterate through every integer in the array, instead of a 1-line autobox/generics-solution. IE: It is possible to do it by hand by NOT using any new features of JDK 1.5, but looses the nice new code cleanliness that 1.5 introduces.
(Incident Review ID: 237968)
======================================================================