Java Reference
In-Depth Information
Bounded Types
In the preceding examples, the type parameters could be replaced by any class type. This is
fine for many purposes, but sometimes it is useful to limit the types that can be passed to
a type parameter. For example, assume that you want to create a generic class that stores a
numeric value and is capable of performing various mathematical functions, such as com-
puting the reciprocal or obtaining the fractional component. Furthermore, you want to use
the class to compute these quantities for any type of number, including integers, float s, and
double s. Thus, you want to specify the type of the numbers generically, using a type para-
meter. To create such a class, you might try something like this:
Search WWH ::




Custom Search