Wildcard (Java): Difference between revisions

Content deleted Content added
Polemyx (talk | contribs)
m Covariance for generic types: fixed incorrect preposition; added required indefinite article
Polemyx (talk | contribs)
m Wildcard as parameter type: corrected non-standard [over]use of prepositions
Line 9:
== Wildcard as parameter type ==
 
In the body of a generic unit, the (formal) type parameter is handled like its [[bounded quantification|upper bound]] (expressed with <code>'''extends'''</code>; <code>Object</code> if not constrained). If the return type of a method is the type parameter, the result (e.g. of type <code>?</code>) can be referenced by a variable of the type of the upper bound (or <code>Object</code>). In the other direction, the wildcard fits to no other type, not even to <code>Object</code>: If <code>?</code> has been applied foras the formal type parameter of a method, no actual parameters can be passed to it. It can be called only by casting of the wildcard reference:
 
<source lang="java5">