I have a class A which is parant of classes AB, AC, AD. Also class A have enum field "type" which can be "A" \ "AB" \ "AC" \ "AD". So, how can i replace this switch with java reflections?
public A f(A aa){
A a;
switch (aa.type){
case A:
a = new A();
break;
case AB:
a = new AB();
break;
case AC:
a = new AC();
break;
case AD:
a = new AD();
break;
}
}
```
Aucun commentaire:
Enregistrer un commentaire