FULL PRODUCT VERSION :
ecalhoun@whirl:~/$ java -version
java version "1.6.0"
Java(TM) SE Runtime Environment (build 1.6.0-b105)
Java HotSpot(TM) Client VM (build 1.6.0-b105, mixed mode, sharing)
ecalhoun@whirl:~/$ javac -version
javac 1.6.0
ADDITIONAL OS VERSION INFORMATION :
Linux, Debian 3.0
Linux whirl 2.6.12.2 #1 SMP Sun Jul 10 16:49:53 PDT 2005 i686 GNU/Linux
A DESCRIPTION OF THE PROBLEM :
When compiling a class containing the following code:
public <T> void process (Action action, Result<T> results[])
{
// unrelated problem stuff happens
Result<T>[] singleResult = results.getClass().cast(Array.newInstance(results.getClass().getComponentType(), 1));
// more problem-unrelated stuff happens
}
one receives a compiler error similar to:
[depend] Deleted 38 out of date files in 0 seconds
[echo] Building...
[javac] Compiling 142 source files to .../classes
[javac] .../SomeClass.java:88: incompatible types
[javac] found : capture#69 of ? extends some.pacakge.Result[]
[javac] required: some.package.Result<T>[]
[javac] results.getClass().cast(Array.newInstance(
[javac] ^
[javac] Note: Some input files use unchecked or unsafe operations.
[javac] Note: Recompile with -Xlint:unchecked for details.
[javac] 1 error
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1. create a function that has a generic type passed in.
2. instantiate an array using the component type of a passed-in array argument of the generic type
3. try and cast the newly-instantiated array to the generic type
4. assign the object resulting from step 3 to a reference of the generic type.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
I expected the compiler to successfully compile the code as the JDK 1.5 compiler did.
ACTUAL -
I received a compiler error similar to:
[depend] Deleted 38 out of date files in 0 seconds
[echo] Building...
[javac] Compiling 142 source files to .../classes
[javac] .../SomeClass.java:88: incompatible types
[javac] found : capture#69 of ? extends some.pacakge.Result[]
[javac] required: some.package.Result<T>[]
[javac] results.getClass().cast(Array.newInstance(
[javac] ^
[javac] Note: Some input files use unchecked or unsafe operations.
[javac] Note: Recompile with -Xlint:unchecked for details.
[javac] 1 error
ERROR MESSAGES/STACK TRACES THAT OCCUR :
I received a compiler error similar to:
[depend] Deleted 38 out of date files in 0 seconds
[echo] Building...
[javac] Compiling 142 source files to .../classes
[javac] .../SomeClass.java:88: incompatible types
[javac] found : capture#69 of ? extends some.pacakge.Result[]
[javac] required: some.package.Result<T>[]
[javac] results.getClass().cast(Array.newInstance(
[javac] ^
[javac] Note: Some input files use unchecked or unsafe operations.
[javac] Note: Recompile with -Xlint:unchecked for details.
[javac] 1 error
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
See description.
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
For now, I am going to have a 2nd generic type, passed-in as a parameter to the function which can be used as a model of what return type to expect.