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

Cast not allowed when both qualifying type and inner class are parameterized

XMLWordPrintable

    • b44
    • generic, x86
    • generic, linux
    • Verified

      Description:
      Compiler throws error for what seems to be a valid cast to a type in which both the qualifying type and inner class are parameterized.

      <code>
      bash-3.00$
      <code>
      bash-3.00$ cat GenericOuter.java
      public class GenericOuter<S> {

          class GenericInner<T> extends LinkedList<T>{

          }
          public static void main(String...args){
             GenericOuter.GenericInner g1 = ( GenericOuter.GenericInner)new LinkedList<String>();
             GenericOuter<String>.GenericInner<String> g2 = ( GenericOuter<String>.GenericInner<String>)new LinkedList<String>(); //Compilation Error
          }

      }


      </code>
      Compilation result is :
      <output>
      GenericOuter.java:8: ')' expected
             GenericOuter<String>.GenericInner<String> g2 = ( GenericOuter<String>.GenericInner<String>)new LinkedList<String>(); //Compilation Error
                                                                                  ^
      GenericOuter.java:8: ';' expected
             GenericOuter<String>.GenericInner<String> g2 = ( GenericOuter<String>.GenericInner<String>)new LinkedList<String>(); //Compilation Error
                                                                                   ^
      GenericOuter.java:8: illegal start of expression
             GenericOuter<String>.GenericInner<String> g2 = ( GenericOuter<String>.GenericInner<String>)new LinkedList<String>(); //Compilation Error

      </output>
      <version>
      /net/sqindia/export/disk09/jdk/7/latest/binaries/solsparc/bin/java -version
      java version "1.7.0-ea"
      Java(TM) SE Runtime Environment (build 1.7.0-ea-b24)
      Java HotSpot(TM) Client VM (build 12.0-b01, mixed mode)

      bash-3.00$ uname -a
      SunOS hrajan 5.10 Generic sun4u sparc SUNW,Sun-Blade-100

            mcimadamore Maurizio Cimadamore
            duke J. Duke
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: