2012-03-20 5 views
0

에서 제네릭 메서드를 가져 오는 것은 리플렉션을 통해 제네릭 클래스에서 일반 (매개 변수화 된) 메서드를 가져올 수 있습니까? 내가 제네릭을 실행하면Java reflection - 비 제너릭 클래스

public interface GenericInterface<T> { 
    public T publicMethod(T arg); 
} 

public class NonGenericClassWithGenericMethods { 
    private <T> void privateMethod(GenericInterface<T> arg) { 

    } 
} 

public class Generics { 
    public static void main(String[] args) { 
     try { 
      NonGenericClassWithGenericMethods.class.getMethod("privateMethod", GenericInterface.class).setAccessible(true); 
     } 
     catch(Exception ex) { 
      ex.printStackTrace(); 
     } 
    } 
} 

, 내가 얻을 : 여기에 내가 무엇을 원하는 샘플의

java.lang.NoSuchMethodException : NonGenericClassWithGenericMethods.privateMethod (GenericInterface)

고마워요

답변

7

.getDeclaredMethod() 대신를 사용해야합니다.은 공개 된 것만 반환합니다.

+0

고맙습니다! 나는 그것이 단지 가시성의 문제라고 알아 차림으로써 타입 지우기에 너무 집중되어있다. :) – lencinhaus

관련 문제