Is it possible to get the type of a generic parameter?
An example:
public final class Voodoo {
public static void chill(List> aListWithTy
Here is another trick. Use a generic vararg array
import java.util.ArrayList;
class TypedArrayList extends ArrayList
{
@SafeVarargs
public TypedArrayList (E... typeInfo)
{
// Get generic type at runtime ...
System.out.println (typeInfo.getClass().getComponentType().getTypeName());
}
}
public class GenericTest
{
public static void main (String[] args)
{
// No need to supply the dummy argument
ArrayList ar1 = new TypedArrayList<> ();
ArrayList ar2 = new TypedArrayList<> ();
ArrayList> ar3 = new TypedArrayList<> ();
}
}