SYNOPSIS
--------
javac fails to compile valid code with "inconvertible types" Error
OPERATING SYSTEM
----------------
All
FULL JDK VERSION
----------------
5.0, Java 6 and JDK 7
REPRODUCTION INSTRUCTIONS
-------------------------
Attempt to Compile the attached testcase with javac.
TESTCASE SOURCE
---------------
import java.util.*;
public class CollectionsExample {
public static void main(String[] args) {
int[] a = {1,2,3,4};
// Fails
Collection<? extends Class<?>> collection = (Collection<? extends Class<?>>) Arrays.asList(a);
// Works
//List list = Arrays.asList(a);
//Collection<? extends Class<?>> collection = (Collection<? extends Class<?>>) list;
}
}
WORKAROUND
----------
Split the failing line over two lines, as shown in the testcase. Despite the two versions of the code being syntactically equivalent, one fails to compile while the other compiles successfully (although it does produce an "unchecked cast" warning).
--------
javac fails to compile valid code with "inconvertible types" Error
OPERATING SYSTEM
----------------
All
FULL JDK VERSION
----------------
5.0, Java 6 and JDK 7
REPRODUCTION INSTRUCTIONS
-------------------------
Attempt to Compile the attached testcase with javac.
TESTCASE SOURCE
---------------
import java.util.*;
public class CollectionsExample {
public static void main(String[] args) {
int[] a = {1,2,3,4};
// Fails
Collection<? extends Class<?>> collection = (Collection<? extends Class<?>>) Arrays.asList(a);
// Works
//List list = Arrays.asList(a);
//Collection<? extends Class<?>> collection = (Collection<? extends Class<?>>) list;
}
}
WORKAROUND
----------
Split the failing line over two lines, as shown in the testcase. Despite the two versions of the code being syntactically equivalent, one fails to compile while the other compiles successfully (although it does produce an "unchecked cast" warning).