需要通过泛型类的反射get方法
问题描述:
我试图使用反映,在这里,我需要在arguments.but我不是为了实现这一目标通过通用类“clazz中”调用方法..需要通过泛型类的反射get方法
在这里例如,我尝试使用类,但这是行不通的
public void log( Class<?> clazz,Throwable throwable, String pattern) {
Method method= CommonsLogger.class.getMethod("info", Class<T>,String.class,Throwable.class);
//try catch removed
}
答
你不能这样做。这应该工作,
CommonsLogger.class.getMethod("info", String.class, Throwable.class)
所以这意味着我可以通过getmethod中的泛型类..这是正确的 – Vish 2011-05-09 07:56:14
是的,确切地说。请阅读http://download.oracle.com/javase/tutorial/java/generics/erasure.html – 2011-05-09 07:57:53