I wonder is it possible to execute method from class on runtime on object of Class?
At first: I have method that returns me a class:
public static Class<?> getClassById(Long id) throws ClassNotFoundException {
if(d.id == 1L) {
return First.class;
} else if(d.id ==2L) {
return Second.class;
} else if(d.id ==3L) {
return Third.class;
} else {
throw new ClassNotFoundException();
}
}
Second: The way I execute it:
Index.GetClassById(1)
which should return me Class. Now I would like to execute method myMethod()
from that class. By the way, each class of (First, Second, Third) have this myMethod()
method.
Please help.
Aucun commentaire:
Enregistrer un commentaire