A Java geek
  • Me
  • Books
  • Speaking
  • Mentions
  • Focus
  • Newsletters

objenesis

A collection of 1 posts
Java

Playing with constructors

Immutability is a property I look after when designing most of my classes. Achieving immutability requires: A constructor initializing all attributesNo setter for those attributes However, this design prevents or makes testing more complex. In order to allow (or ease) testing, a public no-arg constructor is needed. Other use-cases requiring usage of a no-arg constructor include: De-serialization of serialized objectsSub-classing with no constructor invocation of parent classesetc.

May 4, 2014
A Java geek © 2008-2026
v. 1e36702bdd5aadacde73bd395fb1b580e1d1f65d/13988790172
Latest Posts