JDK-6981516 : javac failed to compile generic class cast
  • Type: Bug
  • Component: tools
  • Sub-Component: javac
  • Affected Version: 6
  • Priority: P4
  • Status: Closed
  • Resolution: Duplicate
  • OS: windows_7
  • CPU: x86
  • Submitted: 2010-09-01
  • Updated: 2012-03-20
  • Resolved: 2010-11-08
Related Reports
Duplicate :  
Description
FULL PRODUCT VERSION :
java version "1.6.0_20"
Java(TM) SE Runtime Environment (build 1.6.0_20-b02)
Java HotSpot(TM) Client VM (build 16.3-b01, mixed mode, sharing)

ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows [Version 6.1.7600]

A DESCRIPTION OF THE PROBLEM :
The following code doesn't compile

package com.test;
public class TestCompile {

	public static void main(String[] args) {
		Class<?> clazz = (Class<? extends Generic<? super Object>>) Child.class;
	}
}

interface Generic<T>{}

class Child implements Generic<Integer>{}


output from javac (1.6.0_20):

com\test\TestCompile.java:8: inconvertible types
found   : java.lang.Class<com.test.Child>
required: java.lang.Class<? extends com.test.Generic<? super java.lang.Object>>
                Class<?> clazz = (Class<? extends Generic<? super Object>>) Child.class;
                                                                                 ^
1 error

when used jdk7 b107:

com\test\TestCompile.java:8: inconvertible types
                Class<?> clazz = (Class<? extends Generic<? super Object>>) Child.class;
                                                                                 ^
  required: Class<? extends Generic<? super Object>>
  found:    Class<Child>
1 error



REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------

package com.test;

public class TestCompile {

	public static void main(String[] args) {
		Class<?> clazz = (Class<? extends Generic<? super Object>>) Child.class;
	}
}

interface Generic<T>{
}

class Child implements Generic<Integer>{
}

---------- END SOURCE ----------