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

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

thorough guide for profiling racket code -