Wildcard (Java): Difference between revisions

Content deleted Content added
Line 48:
However, <code>new List<Generic<?>>()</code> is allowed, because the wildcard is not a parameter to the instantiated type <code>List</code>. The same holds for <code>new List<List<?>>()</code>.
 
An array object that is an array of a parameterized type maycan beonly created onlyparameterized by an unconstrained (i.e. with an unbound wildcard type parameter) type as the component type: <code>'''new''' Generic<?>[20]</code> is correct, while <code>'''new''' Generic<SomeType>[20]</code> is not.
 
For both cases, using no parameters is another option. This will generate a warning since it is less type-safe (see [[Raw type]]).
 
== Example: Lists ==