dimanche 18 septembre 2016

How do I get a Class object from a method's type parameter?

I have a type-parameterized method but I can't call getClass on the type-parameterized parameter because it can be null, so the only solution I see is to get the Class from the type parameter itself, somehow:

public <T> Class myMethod(T obj)
{
    //can't do this: return obj.getClass() because null is permitted.
}





Aucun commentaire:

Enregistrer un commentaire