lundi 23 juillet 2018

How can I invoke method from passing string?

I have two methods.

void test1(Object o1, AnotherObject o2) {
    call("test1(o1, o2)");
}

void test2(MyObject 01, MyAnotherObject o2, MyNextObject 03) {
    call("test2(o1, o2, o3)");
}

I want to invoke these methods with same parameters from another method. For example,

void call(String functionStr) {
    // invoke method via functionStr
    // if for test1, invoke -> test1(o1, o2);
    // if for test2, invoke -> test2(o1, o2, o3);
}

void main() {
    call("test1(o1, o2)");
    call("test2(o1, o2, o3)");
}

Please help me how I can call these functions from passed string?

Thanks in advance.





Aucun commentaire:

Enregistrer un commentaire