Consider this hypothetical class (which I found in a online video):
public class Contrived<T extends Number> extends ArrayList<T> {
List <? extends T> values;
......
}
Here the type variables that Contrived
can accept is Number
or some sub-type of Number
. But the class itself inherits from ArrayList
, so what-ever type the class gets, will determine the type of ArrayList
.
Now there is a field called values
, which is List<? extends T values>
. so what does this mean here?
Does the list
can hold anything that extends T
(which in turn extend Number
).
by PECS (producer extends, consumer super)
rule, can I only use this List
to read elements but not add to the list
.
how will the constructor
look like, if I need to pass a list of doubles or some type T
?