What is the use of <T> in public static <T> T addAndReturn(T element, Collection<T> collection){

Viewed 28937

I get confused when I come across a generic method of this sort.

public static <T> T addAndReturn(T element, Collection<T> collection){
    collection.add(element);
    return element;
}

I cannot understand why <T> is required in this method.

Also, what is the difference between generic methods and the methods that use generics syntax?

5 Answers
Related