Import java.lang.reflect.InvocationTargetException;
Import Java.lang.reflect.Method; public class Classutil {/** * methods of performing srcclass by reflection * @param object---The object underlying method is I nvoked from * @param srcclass---class @param paramclasses---parameter class array * @param methodname---Side Name * @param args---The arguments used for the "method" Call * @return * @throws SecurityException * @throws nosuchmethodexception * @throws illegalaccessexception * @throws illegalargumentexception * @throws InvocationTargetException */public static object Executeobjectmethod (object, class<?> Srcclass, Cl Ass<?>[] paramclasses, String methodname, Object ... args) throws SecurityException, Nosuchmethodexception, Illegalaccessexception, IllegalArgumentException, InvocationTargetException {Method method = Srcclass.getmethod (M
Ethodname, paramclasses); Return Method.invoke (object, args); The public static void main (string[] args) throws Exception {//tohexstring static method that performs an integer by reflection.
Out.println (integer.tohexstring (233));
SYSTEM.OUT.PRINTLN (Classutil.executeobjectmethod (null, Integer.class, New Class[]{int.class}, "Tohexstring", 233));
String value = new String ("test");
Executes the length () method of the String Object System.out.println (Executeobjectmethod (Value, Value.getclass (), NULL, "Length");
}
}