【发布时间】:2012-02-22 17:30:56
【问题描述】:
可能重复:
get type of a generic parameter in java with reflection
Java Generics Reflection: Generic field type of subclass
事情就是这样。我有这段代码,我需要以某种方式从对象中获取通用信息。
Class A {
public static String getGenericType(Object o) {
...
}
public static void main(String[] args) {
ArrayList<Integer> list = new ArrayList<Integer>();
getGenericType(list); //this should return "Integer"
}
}
我知道您可以从 Field (Class.getField) 获得泛型类型,但这是不同的。有人知道如何完成吗?提前致谢。
祝你有美好的一天
【问题讨论】:
标签: java generics reflection