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

Nested classes and reified types

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P5
    • Resolution: Fixed
    • Affects Version/s: 6
    • Fix Version/s: 7
    • Component/s: specification
    • Labels:
      None
    • Subcomponent:
    • Resolved In Build:
      rc
    • CPU:
      generic
    • OS:
      generic
    • Verification:
      Verified

      Description

      Oops. I think we just didn't think of this. It would be a shame for both to be illegal, as that would force folks to use raw types. I think javac's behavior is what we intended to specify. Section 4.5.2 failed to take into consideration that sometimes generic types are used in a context where performing a capture conversion is inappropriate. The definition of a "Reifiable Type" failed to consider inner classes too. I suspect there are other places in the spec that nested types are not properly handled.

      -Neal

      On 12/7/06, ... wrote:

      javac accepts this case:
              
              
              class X<T> {
                      class Y<T> {}
              }
              
              
              class B {
                      void f() {
                              X<B>.Y<B> xy = null;
                              boolean b2 = (xy instanceof X<?>.Y<?>);
                      }
              }
              
              
              But rejects this one:
              
              
              class X<T> {
                      class Y<T> {}
              }
              
              
              class B {
                      void f() {
                              X<B>.Y<B> xy = null;
                              boolean b2 = (xy instanceof X<B>.Y<?>);
                      }
              }
              
              
              with the error:
              
              
              t6.java:14: illegal generic type for instanceof
                              boolean b2 = (xy instanceof X<B>.Y<?>);
                                                                ^
              
              
              This seems to be treating X<?>.Y<?> as a type with only unbounded wildcards, but that is not how I read the JLS.
              
              
              - 4.5.2 says that the members of wildcarded types are undefined, so we know that the parent class of Y<?> is not a wildcard.
              
              
              - As far as I can tell, the X<?> in that context is replaced with its capture conversion.
              
              
              So I would expect an error on both of these cases. What am I missing?
      This comment was invalid and has been deleted

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              abuckley Alex Buckley
              Reporter:
              ahe Peter Ahe
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: