Why might one also use a blank constructor?

前端 未结 10 604
傲寒
傲寒 2020-12-16 04:59

I was reading some Java recently and came across something (an idiom?) new to me: in the program, classes with multiple constructors would also always include a blank constr

10条回答
  •  无人及你
    2020-12-16 05:06

    I usually write one constructor that fully initializes the object; if there are others, they all call this(...) with appropriate defaults.

    An object should be 100% initialized and ready for use when it's created.

    Some frameworks, for example Hibernate, demand a no-arg constructor. The way they clash with best practices makes me uneasy sometimes.

提交回复
热议问题