I am trying to achieve something approximating the following:
public class MyClass<E>
{
protected MyClass(Object[] variables)
{
//init
}
public MyClass(Comparator<? super E> comp, Object[] variables)
{
//init
}
public static <K extends Comparable<? super K>, T extends MyClass<K>>
T construct(T example, Object[] variables)
{
return new T(variables);
}
}
Where the Object[] variables is not the actual code, but rather a placeholder for whatever the actual parameters for construction are.
Therein lies my question. I have seen plenty of examples, both with and without reflection, of how to do this when the parameters of T's constructor are known ahead of time, and can thus be specified within construct's parameters. However, I would like to be able to do this even when the parameters of T's constructor are unknown. Is there a way to do this?
I don't particularly care if the solution uses reflection or not so long as it works, but reflection seemed the most likely option.
I am fairly new to reflection as a whole, so I apologize if this question is fairly basic.
Aucun commentaire:
Enregistrer un commentaire