Java Reference
In-Depth Information
Double
, which is not a subclass of
Integer
. This makes the call to
arraysEqual( )
illegal,
and results in a compile-time type-mismatch error.
The syntax used to create
arraysEqual( )
can be generalized. Here is the syntax for a
generic method:
<
type-param-list
>
ret-type meth-name
(
param-list
) { // …
In all cases,
type-param-list
is a comma-separated list of type parameters. Notice that for a
generic method, the type parameter list precedes the return type.
Generic Constructors
A constructor can be generic, even if its class is not. For example, in the following program,
the class
Summation
is not generic, but its constructor is.
The
Summation
class computes and encapsulates the summation of the numeric value
passed to its constructor. Recall that the summation of
N
is the sum of all the whole num-