vendredi 17 février 2017

Reflexively instantiate class with constructor which takes Enum

I have a superclass OpCode and subclasses Add/And..etc

I am trying to reflexively construct the subclasses based on their class name string. The constructor takes an enum defined in the superclass.

I am trying:

OpCode theOpCode = (OpCode) Class.forName("com.sstangle.opCodes." + opCodeName).getConstructor(OpCode.OpEn.class).newInstance(opEn);

which results in

java.lang.NoSuchMethodException: com.sstangle.opCodes.Add.<init>(com.sstangle.opCodes.OpCode$OpEn)
    at java.lang.Class.getConstructor0(Unknown Source)
    at java.lang.Class.getConstructor(Unknown Source)

How do I correctly access the constructor taking the enum?

Thanks





Aucun commentaire:

Enregistrer un commentaire