Java Reference
In-Depth Information
the same type, but a
List
with an element type of
List<?>
could contain
a
List<String>
, a
List<Object>
, and so forth, so capture conversion does
not apply in this case.
Finally, as usual you cannot use a wildcard reference anywhere that the
type of the wildcard needs to be known. For example, given the method
static <T> void addToList(List<T> list, T t) {
/* ... */
}
you cannot pass a reference of type
List<?>
because the inferred type of
T
will be "
captureof ?
" and there is no type compatible with "
captureof ?
"
that you could possibly pass for the parameter
t
. Or looking at it the oth-
er way,
T
will be determined by whatever you pass for
t
, and whatever
it is, it cannot be "
captureof ?
", so the type of
T
would not be uniquely
determined.