Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

  • No mutators (methods that modify internal state)
  • Class must be final
  • Fields must be private and final
  • Defensive copying of mutable components
  • equals, hashCode and toString must be implemented in terms of private fieldsthe fields if you want to compare your objects or use them as keys in e.g. maps

Writing classes that follow these rules is not hard but does involve a fair bit of boiler plate code and is prone to error. Here is what such a class might look like in Java:

...