10.12.2012 Views

The Java Language Specification, Third Edition

The Java Language Specification, Third Edition

The Java Language Specification, Third Edition

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

TYPES, VALUES, AND VARIABLES Type Arguments and Wildcards 4.5.1<br />

Note that using Collection as the type of the incoming parameter, c, would not<br />

be nearly as useful; the method could only be used with an actual parameter that had type<br />

Collection, which would be quite rare. In contrast, the use of an unbounded<br />

wildcard allows any kind of collection to be used as a parameter.<br />

Wildcards are useful in situations where only partial knowledge about the<br />

type parameter is required.<br />

DISCUSSION<br />

Example - Wildcard parameterized types as component types of array types.<br />

public Method getMethod(Class[] parameterTypes) { ... }<br />

Wildcards may be given explicit bounds, just like regular type variable declarations.<br />

An upper bound is signified by the syntax:<br />

? extends B<br />

, where B is the bound.<br />

DISCUSSION<br />

Example: Bounded wildcards.<br />

DRAFT<br />

boolean addAll(Collection

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!