简单的invoke例子
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);}}
Method setMethod = mClassType.getMethod(setMethodName, new Class [] {fields[i].getType()});