I have following code:
public class Test { public static void main(String[] args) { InvocationHandler ih = new MyHandler(); ClassLoader cl = Test.class.getClassLoader(); Class[] mapClass = {Map.class}; ((Map)Proxy.newProxyInstance(cl,mapClass,ih)).put("hello", 11); ((Map)Proxy.newProxyInstance(cl,mapClass,ih)).put("hi", 55); } } class MyHandler implements InvocationHandler { @Override public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { System.out.println("\nInvoked method `" + method.getName() + "` args: " + Arrays.toString(args)); System.out.println(proxy.getClass()); //how to use proxy parameter? and what purposes it can be used? return 42; } } Output:
Invoked method `put` args: [hello, 11] class com.sun.proxy.$Proxy0 Invoked method `put` args: [hi, 55] class com.sun.proxy.$Proxy0 Please tell me:
how can I use the proxy parameter? Non native methods calls yield stackoverflow error.
for what purposes it can be used?
equalsandhashCodeequalsandhashcodemethods on theproxyparameter gives java.lang.StackOverflowError.invoke-method invokes it again.