Java Generics – Generic Methods

Generic Methods

If any method accepts argument which is supposed to be generic or returns object which  is supposed to be generic (like any java collection), then ‘generic method’ can help giving type safe implementation.

Below example shows a method implementation with generic method & without generics. In case of without generic, compiler will give warnings as shown in comments.

Output:

 

Leave a Reply

Your email address will not be published. Required fields are marked *