There is a class which's method returns result with delegate pattern.
class A {
interface ICallback {
callback(String data);
}
void doSomeAction(ICallback cb) {
//some manipuation
if(cb != null) {
cb.callback(response);
}
}
}
The problem here is that A class is in library project and it possible that library will not be attached to the main project. So, the load of A class and call of doSomeAction should be implemented with reflections. But how should proceed with callback? I read about Proxy, but I am still can not understand is it possible to solve it with Porxy. Or is there other solutions for such case?
I tried with Proxy:
Class<?> clazz = Class.forName("com.aa.bb.cc.dd.A$ICallback");
Class<?>[] interfaces = new Class[] { clazz};
Object proxy = Proxy.newProxyInstance(clazz.getClassLoader(), interfaces, handler);
In the last line I am gettin "com.sun.jdi.InvocationException occurred invoking method" error.