Does any of you have a clue why it fails? I've got the correct output but maybe I've made the overkill during iterating through all methods inside SomeInterfaceWithMethodsImpl class?
package com.codegym.task.task32.task3205;
/*
Creating a proxy object
*/
import java.lang.reflect.Proxy;
public class Solution {
public static void main(String[] args) {
SomeInterfaceWithMethods obj = getProxy();
obj.stringMethodWithoutArgs();
obj.voidMethodWithIntArg(1);
/* Expected output:
stringMethodWithoutArgs in
inside stringMethodWithoutArgs
stringMethodWithoutArgs out
voidMethodWithIntArg in
inside voidMethodWithIntArg
inside voidMethodWithoutArgs
voidMethodWithIntArg out
*/
}
public static SomeInterfaceWithMethods getProxy() {
SomeInterfaceWithMethodsImpl obj = new SomeInterfaceWithMethodsImpl();
ClassLoader objClassLoader = obj.getClass().getClassLoader();
Class[] objInterfaces = obj.getClass().getInterfaces();
SomeInterfaceWithMethods proxyObj = (SomeInterfaceWithMethods) Proxy
.newProxyInstance(objClassLoader,
objInterfaces,
new CustomInvocationHandler(obj));
return proxyObj;
}
}