2013-05-24 2 views
0

나는 어떠한 매개 변수가없는 자바 반사에 의한 방법, 호출하는 것을 시도하고있다 :이이 작동Reflection : 매개 변수없이 메서드를 제대로 호출하는 방법?

Method getSelectedCriteriaMethod = multipleSorting.getClass().getDeclaredMethod("getSelectedCriteria", null); 
EstimateSortField selectedCriteria = (EstimateSortField)getSelectedCriteriaMethod.invoke(multipleSorting, null); 

을,하지만 난 컴파일러 경고 점점 오전 :

warning: non-varargs call of varargs method with inexact argument type for last parameter; 
cast to java.lang.Class<?> for a varargs call 
non-varargs call of varargs method with inexact argument type for last parameter; 
cast to java.lang.Object for a varargs call 

무엇입니까 매개 변수가없는 메소드를 호출하는 올바른 방법은 무엇입니까? file.java되지 않은 또는 안전하지 않은 작업을 사용

답변

4
getDeclaredMethod("getSelectedCriteria"); 
invoke(multipleSorting); 
+0

말할 수 있습니다. 주의 : lint를 활성화 할 때'lint를 활성화 할 때':: Xlint : unchecked with details .' 경고 : 원시 타입의 클래스로서 getDeclaredMethod (String, Class ...)의 체크되지 않은 호출이 클래스' – jcubic

+0

@jcubic처럼 보입니다. 'Class cls; '대신'Class cls;'와 같은 것을했습니다. 내가 틀렸다고 생각한다면 아마도 별도의 질문을 할 수있을 것입니다. – johnchen902

6

당신은 단순히 내가 같은 일을 시도하고 주`가지고

selectedCriteria.invoke(multipleSorting);