Get “Class” object from generic type T

后端 未结 6 1801

I want to make generic function that return Object representation of XML document (using JAXB). I need to pass \"class\" object to JAXBContext constructor, but how I can get it

6条回答
  •  刺人心
    刺人心 (楼主)
    2021-02-19 17:13

    You cannot get the class of at run time. Java implements Generics using Type Safe Erasure which means that the understanding of the Generic type is only applied at up through compilation. You must interogate the actual object at run time if you want to get its class.

提交回复
热议问题