samedi 26 décembre 2015

how to refer to instance method

I want to know ways to get reference to an instance method in Java 7

public class MyClass{
    public void myMethod(){
        ....
    }
}

I know I can do this

MyClass.class.getMethod(methodName);

but this technique is prone to error since it relies on String input (i.e. when method name is changed, etc). Is there a more reliable way to refer to a method?

Thanks





Aucun commentaire:

Enregistrer un commentaire