What JAXB needs a public no-arg constructor for?

后端 未结 3 763
忘了有多久
忘了有多久 2020-12-09 09:26

What does JAXB need a public no-arg constructor for, during marshalling?

 Marshaller msh = ctx.createMarshaller();
 msh.marshal(object, System.out);
         


        
3条回答
  •  攒了一身酷
    2020-12-09 10:07

    The same as many frameworks - simplicity and consistency. It allows the library to simple call Class.newInstance() without having to worry about how to specify certain dependencies for a constructor that takes them. JAXB doesn't want to concern itself with full-on Dependency Injection above and beyond the attribute-based setting it already does.

    It's a shame in some ways as it means these classes can't be immutable, but that's the trade-off to be made.

提交回复
热议问题