How to get class of generic type when there is no parameter of it?

后端 未结 5 852
星月不相逢
星月不相逢 2020-12-17 21:04

I just learned about this fine looking syntax

Collections.emptyList()

to get an empty List with elements which a

5条回答
  •  暖寄归人
    2020-12-17 21:42

    You can't, unfortunately. All generics and type parameters are erased in runtime. So in runtime the type of your T is simply Object

提交回复
热议问题