类型转换错误
接口过父类的子类,在强制转换的时候,一定要用接口父类来定义,而不能用实现类。
final ITransfer iTransfer = new ITransferImpl();
ITransfer proxyTransfer = (ITransfer) Proxy.newProxyInstance(iTransfer.getClass().getClassLoader(),iTransfer.getClass().getInterfaces(), new InvocationHandler() {
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
Object returnValue = null;
double money = (Double) args[0];
if ("transfer".equals(method.getName())) {
returnValue = method.invoke(iTransfer, money * 0.8);
}
return returnValue;
}
});
proxyTransfer.transfer(1000);