2017-11-21 13 views
0

클래스를 가진 호출 :반영 -

public class TestClass { 
    public void testMethod() { 
    } 

나는 그 testMethod 메소드를 호출해야하는, 아래의 집행 방법에 전달하고자합니다.

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

하지만 분명히 잘못되었습니다. 올바른 방법은 무엇입니까?

감사합니다.

답변

1

효과가 있지만 잘못 생각한 것 같습니다. testMethod에 구현을 추가하여 실행되었는지 확인하십시오.

executor(TestClass.class); 
: 그대로 반환 voidexecutor(Class clazz) 방법의 종류와 그것을 전화

public void testMethod() { 
    System.out.println("Hi, I have been executed ^^"); 
} 

변경