mardi 19 septembre 2017

How to instanciate constructor of a inner class unknown on compilation time with an abstract outer class constructor

I'm trying to call a constructor which in compilation time has not the class type to instanciate. The problem is that the method invoke needs the enclosing instance but i have not a single clue of how to provide it. Being my outer class abstract i'm not able to give it one.

Class<? extends AbstractOuterClass> enclosingCl;
Constructor<? extends AbstractOuterClass> constructor;
// the constructor has two parameters: int and String
constructor = cl.getConstructor(enclosingCl, int.class, String.class); 

//I need something like this
method.invoke(constructor.newInstance(enclosingCl.instance,-1, null)); 

I have looked some similar implementations like this, this or this, but i haven't reached a satisfactory way of implementing the invoke method





Aucun commentaire:

Enregistrer un commentaire