I am reading multi-level wild cards from AngelikaLangerGenericsFaq. I am pretty confused about the syntax. The document says
The type
Collection<Pair<String,?>>
is a concrete instantiation of the generic Collection interface. It is a heterogenous collection of pairs of different types. It can contain elements of typePair<String,Long>
,Pair<String,Date>
,Pair<String,Object>
,Pair<String,String>
, and so on and so forth. In other words,Collection<Pair<String,?>>
contains a mix of pairs of different types of the formPair<String,?>
.The type
Collection<? extends Pair<String,?>>
is a wildcard parameterized type; it does NOT stand for a concrete parameterized type. It stands for a representative from the family of collections that are instantiations of the Collection interface, where the type argument is of the formPair<String,?>
. Compatible instantiations areCollection<Pair<String,Long>>
,Collection<Pair<String,String>>
,Collection<Pair<String,Object>>
, orCollection<Pair<String,?>>
. In other words, we do not know which instantiation of Collection it stands for.As a rule of thumb, you have to read multi-level wildcards top-down.
I am confused about the following points.
- Can someone elaborate on these three quotes with example. I am totally lost into the syntax
- Document says, para-1 is the concrete instantiation of a generic type and other is not the concrete instantiation? How is that?
- What does it mean to read the wild-cards top down?
- What is the advantage of multi-level wild cards?
Can someone elaborate these points. Thanks.