public class TestMain {
public static void main(String[] args) throws Exception {
//泛型边界
Class<? extends TwoArgs> clazz = new TwoArgs().getClass();
Method [] methods= clazz.getDeclaredMethods();
String methodName = methods[0].getName();
//被调用方法的参数类型
Method method = clazz.getMethod(methodName, new Class[] {String.class , String.class});
System.out.println(method.invoke(new TwoArgs(), "1","111"));
}
}
被调用的方法:
public class TwoArgs {
public String twoArgsMethod(String str1, String str2){
return (str1 == str2)? "OK!" : ("Str2 is : " + str2);
}
}
如果是普通的JavaBean,获得方法参数还可以:
Method setMethod = mClassType.getMethod(setMethodName, new Class [] {fields[i].getType()});