JDK-8030746 : 4.10: Define subtyping for inner classes of parameterized types
  • Type: Bug
  • Component: specification
  • Sub-Component: language
  • Affected Version: 5.0,7,8
  • Priority: P4
  • Status: Open
  • Resolution: Unresolved
  • Submitted: 2013-12-18
  • Updated: 2018-05-17
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.
Other
tbd_majorUnresolved
Related Reports
Relates :  
Relates :  
Relates :  
Relates :  
Relates :  
Relates :  
Description
It is not clear how subtyping among inner classes of parameterized types should be handled:

- Are Foo<Integer>.Bar and Foo<Double>.Bar distinct classes?  Or do we need to assert, for subtyping, that the enclosing class types need to be equal?

- How do we handle Parent<Integer>.Bar vs. Child.Bar (Child extends Parent<Integer>)?

- Do wildcard-parameterized types have inner classes at all?  If so, is Foo<Integer>.Bar a subtype of Foo<? extends Number>.Bar?

- Presumably Foo.Bar is a supertype of Foo<Integer>.Bar?

- Foo<Integer>.Bar is not a parameterized type, right?  Do we ever overlook this fact, and assume a non-parameterized class type is the same as its erasure?  (See, e.g., 5.1.10.)

Generally, much of Chapter 4 needs to be examined with such types in mind.
Comments
A type like C<?>.Inner should be recognized as a wildcard-parameterized type, illegal as a supertype of a class. static class C<T> { class Inner {} } void test(C<?> arg) { class Sub extends C<?>.Inner { // no error in javac 10 public Sub() { arg.super(); } } }
17-05-2018

Per JDK-8203335, anonymous classes have the same property. Notable, it is possible to perform a cast to an anonymous class type via 'this.getClass().cast(obj)`.
17-05-2018

Per JDK-8203337, local class instances can also escape the confines of their local environment, and should be considered parameterized if they are in the scope of type variables (maybe only if those type variables are referenced?). This would mean that casts to the local class type are unchecked.
17-05-2018