mardi 21 novembre 2017

Reflection - invoke

having the class:

public class TestClass {
    public void testMethod() {
    }

I want to pass it to the below executor method, that should invoke its testMethod method.

public class SimpleUnitTester {
    public int executor(Class clazz) {
        clazzObject = clazz.newInstance();
        for (Method m : clazz.getDeclaredMethods()) {
            m.invoke(clazzObject)); <--
        }
    }
}

But its obviously wrong. What is the correct way?

Thanks!





Aucun commentaire:

Enregistrer un commentaire