JDK-6558462 : Nested classes and reified types
  • Type: Bug
  • Component: specification
  • Sub-Component: language
  • Affected Version: 6
  • Priority: P5
  • Status: Closed
  • Resolution: Fixed
  • OS: generic
  • CPU: generic
  • Submitted: 2007-05-16
  • Updated: 2014-02-26
  • Resolved: 2011-07-21
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 7
7 rcFixed
Related Reports
Relates :  
Relates :  
Relates :  
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

Comments
EVALUATION Capture conversion is not applied to the argument of instanceof. Further, capture conversion is applied to the type of a field but not other members. So I think this is the only place where a type is parameterized with wildcards yet its members (namely, non-static member types) can be denoted. 4.7 Reifiable Types should add a clause: "It is a nested type that would be reifiable according to these rules if it was a top-level type, and the invocation of its immediately lexically enclosing type is reifiable." (X<?> is reifiable, so X<?>.Y<?> is reifiable. X<?>.Y<Object> is not reifiable because Y<Object> is not reifiable as a top-level type.) We want to allow X<?> to have a member Y<?> (no bounds please) or Y, so 4.5.2 should say "If any of the type arguments to a parameterized type are wildcards, then: - the type of its ***field and method*** members and constructors is undefined. - the type of a class or interface member is the declared type of the member, where all type arguments are unbounded wildcards if the declared type is generic."
10-09-2007