如何使用反射在列表中获取名称参数[复制]

时间:2022-06-12 21:38:45

This question already has an answer here:

这个问题在这里已有答案:

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();