mercredi 3 avril 2019

Java reflection : how to call a method with private interface as argument?

In Java, I usually call a method by reflection which uses an interface as argument by building my arguments using : Method method = theClass.getMethod("methodName", new Class[]{IAnyInterface.class});

But I don't know how to do this when the interface is nested in a private class : JSomething.INestedInterface, where JSomething is private :

private class JSomething {

public void init(INestedInterface iSomething) {
    ...
}

public interface INestedInterface {
    public void notify();
}

....

}

Here using this doesnt even compile as the interface is not accessible : Method method = theClass.getMethod("init", new Class[]{JSomething.INestedInterface.class});

I've created a proxy handler ready to be called, but I'm stuck trying to build a "class" argument when I can't use the nested interface name, any advice ?

Thanks.





Aucun commentaire:

Enregistrer un commentaire