2015-01-11 5 views
0

리플렉션을 사용하여 Resources $ Theme 클래스의 메소드를 호출하려고하지만이를 수행 할 수 없습니다.리플렉션이 클래스의 모든 메소드를 표시하지 않습니다.

다음은 내가 newTheme는(), getTheme 및 기본 생성자를 사용할 수 있는지 확인할 수 있습니다 테마 클래스를 확인에 내 코드

Class inner=Class.forName("android.content.res.Resources$Theme"); 
      Constructor []ins=inner.getConstructors(); 
      // Method met=inner.getDeclaredMethod("newTheme", null); 
      Method [] mer=inner.getMethods(); 
      for(Method m:mer){ 
       String name=m.getName(); 
       System.out.println(name); 
      } 
      // Object obj= met.invoke(null, null); 

      for(Constructor con:ins){ 
       String name=con.getName(); 
       System.out.println(name); 
      } 

입니다. 첫 번째 주석 처리 된 행을 활성화하면 NoSuchMethodFoundException 오류가 발생합니다. 그래서 클래스에서 모든 메소드 이름을 얻으려고 시도하고 newTheme(), getTheme()와 같은 몇 가지 메소드를 포함하지 않는다는 것을 알았다. 또한 내 생성자 목록이 비어 있습니다.

누군가 그 이유를 설명 할 수 있습니까? 메서드 (newTheme) 중 하나가 final이고 다른 하나 (getTheme)가 하나의 주석 (@ ViewDebug.ExportedProperty (category = "theme", hasAdjacentMapping = true)을 가짐)을 보았습니다. 또한 생성자/패키지를 무엇이/이전/패키지로 제공된다. 정의 경우에도 내가 생성자 목록이 표시되지 않는 이유는 무엇입니까? 을 의미/여기에 의미?

+0

확인을 getMethods는/getDeclaredMethods, 생성자에 대한 동일한 betweeen의 차이를. – laune

+0

getDeclaredMethods의 결과에도 나를 언급 한 메소드가 없습니다. –

+0

getMethods에는 wait와 같은 모든 객체 메소드가 포함되어 있습니다. –

답변

0

시도가 getDeclaredMethodsgetDeclaredConstructors를 사용하는. 목은 * 개인 반환합니다 , public, protected 및 package-protected 메서드가 있으며 getMethodsgetConstructors은 public 메서드 만 반환합니다.

또한 다음과 같은 방법으로 반복하는 클래스 계층 구조를 시도 :

while (targetClass != null) { 
    Method[] methods = targetClass.getDeclaredMethod(setterMethodName, type); 
    // do something with methods here 
    targetClass = targetClass.getSuperclass(); 
} 
+0

확인했지만 그 일은 일어나지 않았습니다. 아직도 나는 나에 의해 언급 된 방법을 볼 수 없다. –

+0

내 대답이 업데이트되었습니다. 클래스 계층 구조를 반복합니다. –

관련 문제