Java Reference
In-Depth Information
11.7. Class Extension and Generic Types
Generic types add an extra dimension to the type system, and force you
to think more deeply about how to define classes and interfaces and how
to use existing classes and interfaces. You can extend a non-generic type
to produce either a generic or a non-generic subtype. You can extend a
generic type to produce a generic subtype, or you can extend a specific
parameterized type to yield a non-generic subtype, or you can combine
both. This degree of flexibility can be overwhelming, but the key thing to
focus on is what abstraction your new class or interface represents and
what abstraction the class or interface you are inheriting from repres-
ents.
For example, the List<E> interface is generic and represents a list of ele-
ments of some kind. If you implement that interface then you may be
providing a general-purpose implementation that can deal with arbitrary
element types, and in that case your class would also be a generic class,
such as
class GeneralList<E> implements List<E> { /* ... */ }
Or you may be providing a specialized implementation that has been
hand-crafted to deal with a particular kind of element, say String , and so
it won't be generic itself and will implement the parameterized interface
List<String> :
class StringList implements List<String> { /* ... */ }
An existing non-generic class, such as AbstractEventService , may provide
base functionality that you have to extend to use a framework within
your application. You might define a concrete implementation that has no
need of generics:
 
Search WWH ::




Custom Search