How to check the type of method parameter when use reflection in java -
i have method that:
public void get(date date) and use reflection, , want check type of parameter, make sure whether type of java.util.date, that:
class<?> parameterstype = method.getparametertypes(); // check if (parameterstype[].equals(java.util.date.class)) { // } i want know, there other way?
if want know if method has single parameter of type date can do
class<?>[] parameters = method.getparametertypes(); if (parameters.length == 1 && parameters[0] == date.class)) { // } if might better do
if (parameters.length == 1 && parameters[0].isassignablefrom(date.class)) because find out if method has single parameter accept date. example, parameter of type object, cloneable or comparable<?> , still pass date.
Comments
Post a Comment