Generics enable classes and interfaces to be parameters when an interface, class or method is defined. If you use generics, strong type checking is performed by the Java compiler
The code snippet without generics
Code snippet with generics:
Generic Class
In a generic class declaration a type parameter section is added with non-generic class declaration.
The type parameters of generic methods need to be set as type parameters of the class containing the methods. If multiple parameters are used, they should be separated by commas. Thus generic classes are known as parameterized classes or parameterized types.
A generic class is defined below
Generic Method
A generic method can be called with different types of arguments. The compiler handles appropriate method call for different types arguments to the generic methods.
A generic method's body is declared alike a non-generic method
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.