Wednesday, September 12, 2007

Restriction to Use Generics

Enums, Exceptions and Anonymous classes are not applicable to use with Generics. The reason being is

1) An enum type and its enum values are static. Since type parameters cannot be used in any static
context, the parameterization of an enum type would be pointless

2) Generic exception or error types are disallowed because the exception handling
mechanism is a runtime mechanism and the Java virtual machine does not know anything
about Java generics

3) Anonymous classes do not have a name, but the name of a generic class is needed for declaring an
instantiation of the class and providing the type arguments

No comments: