United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
Bug ID: JDK-6480391 Unbounded wildcard '?' means '? extends Object'
JDK-6480391 : Unbounded wildcard '?' means '? extends Object'

Details
Type:
Enhancement
Submit Date:
2006-10-10
Status:
Closed
Updated Date:
2014-02-26
Project Name:
JDK
Resolved Date:
2013-08-23
Component:
specification
OS:
generic
Sub-Component:
language
CPU:
generic
Priority:
P5
Resolution:
Fixed
Affected Versions:
6
Fixed Versions:
8

Related Reports
Duplicate:
Relates:
Relates:
Relates:
Relates:

Sub Tasks

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
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.
                                     
2013-03-22
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
                                     
2013-12-17
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.
                                     
2006-12-11



Hardware and Software, Engineered to Work Together