Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-6981516

javac failed to compile generic class cast

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P4 P4
    • None
    • 6
    • tools
    • x86
    • windows_7

      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 ----------

            mcimadamore Maurizio Cimadamore
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: