Java Reference
In-Depth Information
Now, any implementing class must pass to Containment a type argument also having
the same bound. For example, now MyClass must be declared as shown here:
Pay special attention to the way the type parameter T is declared by MyClass and then
passed to Containment . Because Containment now requires a type that extends Number ,
the implementing class ( MyClass in this case) must specify the same bound. Furthermore,
once this bound has been established, there is no need to specify it again in the implements
clause. In fact, it would be wrong to do so. For example, this declaration is incorrect and
won't compile:
Once the type parameter has been established, it is simply passed to the interface without
further modification.
Here is the generalized syntax for a generic interface:
interface interface-name < type-param-list > { // …
Here, type-param-list is a comma-separated list of type parameters. When a generic inter-
face is implemented, you must specify the type arguments, as shown here:
class class-name < type-param-list >
implements interface-name < type-param-list > {
Try This 13-1 Create a Generic Queue
Search WWH ::




Custom Search