-
Enhancement
-
Resolution: Other
-
P5
-
None
-
None
-
None
Currently wildcards can only have one bound, whereas type variables can have
multiple bounds:
<T extends Number & Cloneable> void m(List<T> l);
A similar method could be expressed using wildcards with multiple bounds:
void m(List<? extends Number & Cloneable> l);
Among the benefits of using wildcards over type variables are:
1. The signature becomes simpler since you do not need to add a type variable
to express the constraints on l.
2. The signature using wildcards states implicitly that you do not intent to
modify l (at least not add new non-null elements).
3. It is not necessary to understand the rules of inference to read the
signature.
###@###.### 2004-05-25
multiple bounds:
<T extends Number & Cloneable> void m(List<T> l);
A similar method could be expressed using wildcards with multiple bounds:
void m(List<? extends Number & Cloneable> l);
Among the benefits of using wildcards over type variables are:
1. The signature becomes simpler since you do not need to add a type variable
to express the constraints on l.
2. The signature using wildcards states implicitly that you do not intent to
modify l (at least not add new non-null elements).
3. It is not necessary to understand the rules of inference to read the
signature.
###@###.### 2004-05-25
- relates to
-
JDK-8061410 Multiply-bounded reference type expressions
- Closed
-
JDK-8061427 Type variables should have lower/super bounds
- Closed