This question already has an answer here:
这个问题在这里已有答案:
- How can I determine the type of a generic field in Java? 6 answers
- Get generic type of java.util.List 14 answers
如何确定Java中通用字段的类型? 6个答案
获取java.util.List的通用类型14个答案
I have a Lot List like this:
我有这样的地段清单:
..
public java.util.List<ComId> comIds;
public java.util.List<Notification> notifications;
public java.util.List<ProductItem> productItems;
..
And i using java reflection to read this.
我用java反射来读这个。
Input:
for (Field f : fields) {
Class<?> type = f.getType();
String genName = f.getGenericType().getTypeName().toString();
}
I get such a result:
我得到了这样的结果:
java.util.List<my.package.Customer.ComId>
java.util.List<my.package.Customer.Notification>
java.util.List<my.package.Customer.ProductItem>
..
I just want get only:
我只想得到:
ComId
Notification
ProductItem
..
How i can do that?
我怎么能这样做?
1 个解决方案
#1
-1
Try this:
String genName = f.getGenericType().getActualTypeArguments()[0].toString();
#1
-1
Try this:
String genName = f.getGenericType().getActualTypeArguments()[0].toString();