![](/img/trans.png)
[英]Paramterized class, how to reference the paramterized type of something passsed as a paramterized type
[英]get paramterized type java reflection
无论如何有使用反射获取字段的内部类型参数
例如:
public final class Main
{
class A
{
public int aX;
public String aS;
}
class B
{
public Set<A> bSet;
}
public static void main(String[] args)
{
Class clazz = B.class.getField("bSet").getType();
}
};
使用上面的我只能得到“ Set”,反正我也可以得到A? 谢谢
反射确实可以为字段(和类等)传递完整的参数化类型。 只是在运行时删除其类型的对象 。
调用getGenericType
而不是getType
并开始阅读javadoc。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.