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

Cast to partially raw type(rare type) should not be allowed

XMLWordPrintable

    • generic
    • generic

      Description:
      JLS Section 4.8 states that a generic inner class of a raw type can itself only be used as a raw type,it is not possible to access Inner as partially raw type (a "rare" type).But in the following code,cast to a partially raw type is allowed by the compiler. Compiler should instead be throwing an error.

      <code>
      bash-3.00$
      <code>
      bash-3.00$ cat Outer.java
      <code>
      class Outer<T>{
          
           class Inner<S>{
          }
           <R> void met(R r){
               
           }
           void met2(){
      Outer.Inner oo2 = (Outer.Inner<String> )null; //Cast to partial raw type should not compile
      // Outer.Inner<String> oo2 = null; // This does not compile on uncommenting, as expected.
      Outer<String>.Inner<String> oo = null;
               this.met((Outer.Inner<String> )oo);//Cast to partial raw type should not compile
           }
          
                    
      }
      </code>
      Compiles fine. Compiler should actually be throwing an error as the cast type is illegal.

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