mercredi 12 décembre 2018

Reflectively create an anonymous class

I intend to import a library(jar) using my custom ClassLoader and it turns out the requirement is there to set a listener on one of the classes, like,

Class<?> clazz = getInitializerClass();
Object initializer = clazz.newInstance();

// I would like the below listener to be set on this initializer reflectively
setOnInitListener(new OnInitCompleteListener(){
    @Override
    public void onInit(){
    }
}

The issue is that I don't have the listener available as a import and all I can get is a OnInitCompleteListener.class dynamically by classloading on the fly.

How can I achieve the above?

Note: I am willing to go any limits to achieve the same but a simple approach would be appreciated.





Aucun commentaire:

Enregistrer un commentaire