Java Reference
In-Depth Information
The output is shown here:
Notice how NumericFns is now declared by this line:
Because the type T is now bounded by Number , the Java compiler knows that all objects
of type T can call doubleValue( ) because it is a method declared by Number . This is, by
itself, a major advantage. However, as an added bonus, the bounding of T also prevents
nonnumeric NumericFns objects from being created. For example, if you remove the com-
ments from the lines at the end of the program, and then try re-compiling, you will receive
compile-time errors because String is not a subclass of Number .
Search WWH ::




Custom Search