Recently I was reading the following piece of code from oracle collection tutorial when i came across this piece of code.
public static <E> Set<E> removeDups(Collection<E> c) {
return new LinkedHashSet<E>(c);
}
I was not able to understand why the returned value is something
<E> Set<E> and not just Set<E> ?
The return type is, in fact, simply
Set<E>.The other
<E>is there to indicate that this is a generic method, and to state thatEis a parameter to the generic. Without this<E>, the compiler would assume thatEis an existing class, and would try to locate it (producing an error if no class namedEis in scope).