January 2011
Intermediate to advanced
1648 pages
70h 30m
English
Not just interfaces can be used to constrain a type parameter to only those types that implement it; base classes can also be used to enforce a similar relationship. You can constrain a type parameter such that only subclasses of a specified base class can be used to instantiate the parameter:

Enforcement of the constraint is similar to what we’ve seen with interfaces. The following will work fine, for the obvious reason that every Jonagold is an Apple:
![]()
Notice that generics go hand in hand with the well-known capability to ...
Read now
Unlock full access