How to Get class of Elements that List Contains?

前端 未结 4 380
醉梦人生
醉梦人生 2021-01-18 01:47

I have a list like that:

private List myList = new ArrayList();

I want to get the .class of T. How can I do that?

4条回答
  •  醉梦人生
    2021-01-18 02:24

    You can't because of type erasure. The generic type is not known at runtime (it's 'erased'), it's only used at compile time.

    This is a major difference between java generics and c# generics for example.

提交回复
热议问题