Can anyone explain what does the return type mean in the following code
public static <T> ArrayList<T> a()
{
return null;
}
and
public static <String> ArrayList<Vector> a()
{
return null;
}
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.
The first occurance of
<T>introduces a type parameter which will be available within the method.The actual return type is
ArrayList<T>, whereTis same as the one in the first.You can read about it here – Generic Methods.
In the second one:
Even though you have introduced a generic type parameter (i.e.
String, which is not an actual type or argument likejava.lang.String) you are not using it. And, also the method always returns anArrayList<Vector>(ArrayListofVectors).