Generics
Generics
Introduction
J2SE 5 added many new feature to Java, the one of them
is generics.
Through the use of generics, it is possible to create
classes, interfaces, and methods that will work in a type-
safe manner with various kind of data.
What Are Generics?
Generics abstract over Types
Classes, Interfaces and Methods can be Parameterized
by Types
Generics provide increased readability and type safety
Generic Methods:
You can write a single generic method declaration that can be called
with arguments of different types. Based on the types of the arguments
passed to the generic method, the compiler handles each method call
appropriately. Following are the rules to define Generic Methods:
class class-name<type-param-list>
{
// …
}