我有问题。我创建了一个新的调用处理程序,我想设置方法的(输出)参数,但不成功。非常感谢!
我的代码:
class MyInvocationHandler extends InvocationHandler {
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
if (method.getName().equals("example")) {
args[0] = "abcd"; //not successful
return "example";
}
}
}
interface Test {
String example(String s);
}
public static void main(String[] args) {
MyInvocationHandler myhandler = new MyInvocationHandler();
Test test = (Test) Proxy.newProxyInstance(loader, new Class[]{Test.class}, myhandler);
String a = new String("ab");
String ret = test.example(a);
System.out.println(a); //a value is ab, not abcd! Why?
}