java - Is the unbounded wildcard type used only to create references? -


i have seen lot of cases in, ? type used create references. , not able add objects other null. so, use of '?', create references?

also, need / use of giving option add null? have implemented no add() method @ all, right? reason giving option of adding null list < ? > ?

list generic interface, , same interface regardless of generic type. such, implementors required redefine methods in it. far being able add null "unbounded" list, it's not matter of methods as requisiste of respecting interface:

the unbound generic wildcard allows reference list (or other generic class) passed around methods without requiring compile-time knowledge of specific type contain. however, contract of generic must still respected. poses no big problem read operations, since whatever in list, (also) java.lang.object. on other hand, insert operations impossible, since lacking informations accepted types, no type can accepted - e.g. list can accept strings, object else - number example, , cannot accepted safely.

null works safely since (assuming list accept null values), value that's valid put inside list (a null can cast valid type).

edit: since noticed didn't answer question: yes, <?> wildcard (and extended forms <? extends x> , <? super x> valid when defining references, , cannot used in generic instantiation.


Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -