mardi 14 avril 2015

How to check the type of method parameter when use reflection in java

I have a method like that:



public void get(Date date)


And I get it use reflection, and I want to check the type of parameter, make sure whether it is a type of java.util.Date, I do it like that:



Class<?> parametersType = method.getParameterTypes();
// check it
if (parametersType[].equals(java.util.Date.class))
{
// do something
}


I want to know, are there any other way?






Aucun commentaire:

Enregistrer un commentaire