Thursday, 5 September 2013

How knows JVM the generics type paramter without arguments?

How knows JVM the generics type paramter without arguments?

I have a generics factory method.
public static <T> List<T> create(){
return new ArrayList<T>();
}
But it hasn't arguments/parameters.
I don't give the type paramter for the function, but it knows the
appropriate type without any arguments.
public static void main(String[] args){
List<Integer> intlist = create(); //it is an Integer List
List<String> stringlist = create(); //it is a String List
}

No comments:

Post a Comment