Possible Duplicate:
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 - 在 Java 中通过反射获取通用信息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9399925/