Java: general method and return type

Can anyone explain what the return type means in the following code

public static <T> ArrayList<T> a()
{       
       return null;
} 

and

public static <String> ArrayList<Vector> a()
{       
       return null;
} 
+5
source share
1 answer
public static <T> ArrayList<T> a() 

In the first case <T>, a type parameter is entered that will be available within the method.

The actual type of return ArrayList<T>, where Tthe same as in the first.

You can read about it here - General Methods .

In the second:

public static <String> ArrayList<Vector> a() {

Even though you entered a parameter of a general type (i.e. String, which is not an actual type or argument, for example java.lang.String), you do not use it. And also the method always returns ArrayList<Vector>( ArrayListof Vectors).

+7
source

All Articles