Linus Dietz wrote:Hi Alexandre,
getting immutability right is not easy and in my opinion cannot be done in an automated way. But before we go into deeper discussion here: what is your definition of immutability?
Stephan van Hulst wrote:Welcome to CodeRanch!
Alexandre Queiroz de Oliveira wrote:To make a class immutable you can turn all attributes into private, do not create any setter method, and then just use the constructor or a Builder to set the attributes.
This is not complete. You need to make sure that the fields are immutable as well, or that you perform defensive copies in the constructors and getters.