java - Why addAll(Collection<? extends E>) is used to put elements in a collection while wildcard extends is generally suggested for Get? -
i point “? extends e” means is ok add members of collection elements of type subtype of e. hence list , addall(all values of list) hold good. why generalised "use extends wildcard when values out of structure" per , put principle ?
when addall
parameter collection
, you're "getting" elements in collection
parameter , adding them collection. therefore "producer extends (consumer super)" still applies here.
by enforcing generic <? extends e>
, ensuring elements in parameter instanceof e
, , can therefore added collection<e>
.
Comments
Post a Comment