Possible Duplicate:
What does List<?> mean in java generics?
What does the question mark in Java generics' type parameter mean?
Apologies but it was difficult trying to search for <?>
.
What does mean in regards to Java generics? I understand <A extends B>
and <A super B>
, but I have never seen this question mark on its own before.
In object-oriented programming, a class is a basic building block. It can be defined as template that describes the data and behaviour associated with the class instantiation.
super T denotes an unknown type that is a supertype of T (or T itself; remember that the supertype relation is reflexive). It is the dual of the bounded wildcards we've been using, where we use ? extends T to denote an unknown type that is a subtype of T .
super is a lower bound, and extends is an upper bound.
T is meant to be a Type. E is meant to be an Element ( List<E> : a list of Elements) K is Key (in a Map<K,V> ) V is Value (as a return value or mapped value)
<?>
is a shorthand for <? extends Object>
, it's also known as an unbounded wildcard. So you can specify any type of object in your generic.
For example the List
class is declared as List<?>
, because it can be a list of anything you want.
Resources:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With