I am just reading through collection java tutorial and wondering why the <E> is needed after static?
public static<E> Set<E> removeDups(Collection<E> c) {
return new LinkedHashSet(c);
}
Thanks,
Sarah
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
For readability, there’s usually a space between the static and the generic parameter name.
staticdeclares the method as static, i.e. no instance needed to call it. The<E>declares that there is an unbounded generic parameter called E that is used to parameterize the method’s arguments and/or return value. Here, it’s used in both the return type,Set<E>to declare the method returns a Set of E, and in the parameter,Collection<E>indicating that the method takes a collection of E.The type of E is not specified, only that the return value and the method parameter must be generically parameterized with the same type. The compiler determines the actual type when the method is called. For example,
If you attempt use different parameterized types for the two collections, such as
this will generate a compiler error, since the generic parameters do not match.