mercredi 18 novembre 2015

How to create new instance of a class by passing Object[] instead of parameter list with reflection

Do you have any clue about how to write such method?

public abstract class AbstractClass{}

public class TrialClass extends AbstractClass{
    public TrialClass(final String a, final String b){}
    public TrialClass(final String a, final String b, final String c){}
}

public class getNewInstance(final Class<? extends AbstractClass> clazz, Object... constructorParameters){
    //???
}

TrialClass trialClass = getNewInstance(TrialClass.class, "A", "B");





Aucun commentaire:

Enregistrer un commentaire