compatible array to Gen( ) when an object is created and assign that reference to vals,
as the program does in this line:
This works because the array passed to Gen() has a known type, which will be the same
type as T at the time of object creation. Inside main( ), notice that you can’t declare an
array of references to a specific generic type. That is, this line
won’t compile.
Generic Exception Restriction
A generic class cannot extend Throwable. This means that you cannot create generic
exception classes.
CONTINUING YOUR STUDY OF GENERICS
As mentioned at the start, this chapter gives you sufficient knowledge to use generics
effectively in your own programs. However, there are many side issues and special
cases that are not covered here. Readers especially interested in generics will want to
learn about how generics affect class hierarchies, runtime type comparisons, and
overriding, for example. Discussions of these and other topics are found in my book
Dostları ilə paylaş: