JDK-6480391 : Unbounded wildcard '?' means '? extends Object'
  • Type: Enhancement
  • Component: specification
  • Sub-Component: language
  • Affected Version: 6
  • Priority: P5
  • Status: Closed
  • Resolution: Fixed
  • OS: generic
  • CPU: generic
  • Submitted: 2006-10-10
  • Updated: 2021-06-02
  • Resolved: 2013-08-23
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 8
8Fixed
Related Reports
Duplicate :  
Relates :  
Relates :  
Relates :  
Relates :  
Relates :  
Relates :  
Description
The introduction of the capture conversion simplified a lot of things. One of the things it did is make "?" equivalent to "? extends Object". Unfortunately, JLS3 doesn't say they are equivalent. It should because, for example, 4.5.1.1, which describes type argument containment, does not address the unbounded wildcard case. Similarly, the definition of Icta on page 465 seems to be missing a case for an unbounded wildcard. I expect there are others.

Comments
For clarity, augment: ? extends T <= ? extends S if T <: S with: ? extends T <= ? For correctness, add: ? super T <= ? and then for clarity, augment it with: ? super T <= ? extends Object
17-12-2013

Consensus from some additional discussion is that we want a special rule that says '? extends Object' is _the same as_ '?' (that is, '? extends Object' is an unbound wildcard). This should have the effect of all of the following, without having to make a special exception for each case: - Foo<?> <: Foo<? extends Object> - List<Foo<?>> <: List<Foo<? extends Object>> - Foo<? extends Object> is reifiable - expr instanceof Foo<? extends Object> is legal - A method with type parameter <T extends Foo<?>> can override a method with type parameter <T extends Foo<? extends Object>> As this is a language change, it will require some extra testing and some compiler changes. javac already does it in some cases, though.
22-03-2013

EVALUATION ? should be considered equivalent to ? extends Object. I will note this at the end of the text about bounds for wildcards in 4.5.1. Consider: class Foo<T extends Integer> {} void m(Foo<?> f) {} With m's parameter being Foo<?>, JLS 5.1.10 specifies that it undergoes capture conversion to Foo<S extends Integer>, where S is a fresh type variable. If m's parameter was Foo<? extends Object>, it would still undergo capture conversion to Foo<S extends Integer>, because S's upper bound would be glb(Object,Integer). Hence, Foo<?> is semantically equivalent to Foo<? extends Object>. The bound of T in the declaration of class Foo is irrelevant.
11-12-2006