Get “Class” object from generic type T

后端 未结 6 1803

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条回答
  •  Happy的楠姐
    2021-02-19 17:16

    Don't listen to the others... you CAN get it.

    Simply change the type of the jaxbClass parameter to Class:

    public  T readXmlToObject(String xmlFileName, Class jaxbClass) {
       JAXBContext context = JAXBContext.newInstance(jaxbClass);
       .......
    }
    

提交回复
热议问题