import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
//新建一個計算器的類
public int add(Integer i,Integer j){
return i+j;
}
public int subject(Integer i,Integer j){
return i-j;
}
public int multiply(Integer i,Integer j){
return i*j;
}
public int devide(Integer i,Integer j){
return i/j;
}
public static void main(String[] args) throws ClassNotFoundException, InstantiationException, IllegalAccessException, SecurityException, NoSuchMethodException, IllegalArgumentException, InvocationTargetException {
//利用反射,加載類
Class clz = Class.forName("fft.property.copy.Calculator");
System.out.println("clz="+clz);
//獲取類對應的對象
Calculator calculator = (Calculator) clz.newInstance();
//獲取對象對應地方方法
System.out.println("mt="+mt);
//逆向調用 方法調用對象
System.out.println(mt.invoke(calculator, new Object[]{4,5}));
}
}