This line:
return (SomeInterfaceWithMethods)Proxy.newProxyInstance(new CustomInvocationHandler(original));
gives the following error:
Error in com/codegym/task/task32/task3205/Solution.java on line 28
method newProxyInstance in class java.lang.reflect.Proxy cannot be applied to given types;
required: java.lang.ClassLoader,java.lang.Class<?>[],java.lang.reflect.InvocationHandler
found: com.codegym.task.task32.task3205.CustomInvocationHandler
reason: actual and formal argument lists differ in length
package com.codegym.task.task32.task3205;
import java.lang.reflect.Proxy;
/*
Creating a proxy object
*/
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() {
SomeInterfaceWithMethods original = new SomeInterfaceWithMethodsImpl();
return (SomeInterfaceWithMethods)Proxy.newProxyInstance(new CustomInvocationHandler(original));
}
}