lundi 5 avril 2021

Can I call a method without specifying a method type with reflection?

I read the name of the calling method and the content of the input parameter from the file. I want to call a method with reflection, but I don't specify the specific type. Can I do that?

public class FunctionA {

    public String printf(String s) {
        return "functionA:" + s;
    }

}

Method method = clazz.getMethod("printf");
// Method method = clazz.getMethod(invocation.getMethodName(), paramClasses);
return method.invoke(clazzInstance, paramObjects);




Aucun commentaire:

Enregistrer un commentaire