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;
}
public static <T> ArrayList<T> a()
The first occurance of <T>
introduces a type parameter which will be available within the method.
The actual return type is ArrayList<T>
, where T
is same as the one in the first.
You can read about it here - Generic Methods .
In the second one:
public static <String> ArrayList<Vector> a() {
Even though you have introduced a generic type parameter (ie String
, which is not an actual type or argument like java.lang.String
) you are not using it. And, also the method always returns an ArrayList<Vector>
( ArrayList
of Vector
s).
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.