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

后端 未结 5 855
星月不相逢
星月不相逢 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:38

    retValue.getClass().getName() will always return the runtime type of the object and not the class name of the parameter type.

    If you want to grab the parameter class, there's no other way than to use your first solution. (That is, pass the class object explicitly.)

提交回复
热议问题