Alexandre Queiroz de Oliveira

Greenhorn
+ Follow
since Feb 19, 2018
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Alexandre Queiroz de Oliveira

Is it ok to handle POJOs in package "port in" or should it be restricted to POJOs in the model package?
If I should use only POJOs of the model package, Where should I call the mappers, inside the service or in a controller?
3 weeks ago

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?

Cheers,
Linus



What I mean by immutability is not only become the references immutable with use of key word “final”, but also avoid something like this:
object.getSomething.setAnotherThing(1);
3 years ago
I saw some frameworks like Lombok, but I think this only work with immutable references nor with immutable objects.
Is there a convenient framework or something like that to work with immutable objects ?
3 years ago

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.



So, do you think that turning the attributes into final this will become complete?
3 years ago
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.
Here a simple example:

3 years ago