Java: how do I get a class literal from a generic type?

后端 未结 8 1452
北荒
北荒 2020-11-22 07:18

Typically, I\'ve seen people use the class literal like this:

Class cls = Foo.class;

But what if the type is generic, e.g. List?

8条回答
  •  旧巷少年郎
    2020-11-22 08:11

    You can manage it with a double cast :

    @SuppressWarnings("unchecked") Class> cls = (Class>)(Object)List.class

提交回复
热议问题