Java Reference
In-Depth Information
Here, class
A
is extended by classes
B
and
C
, but not by
D
.
Next, consider the following very simple generic class:
Gen
takes one type parameter, which specifies the type of object stored in
ob
. Because
T
is unbounded, the type of
T
is unrestricted. That is,
T
can be of any class type.
Now, suppose that you want to create a method that takes as an argument any type of
Gen
object so long as its type parameter is
A
or a subclass of
A
. In other words, you want
to create a method that operates only on objects of
Gen<
type
>
, where
type
is either
A
or a
subclass of
A
. To accomplish this, you must use a bounded wildcard. For example, here is