What I see in code in 99% of cases, private fields and lombok getters/setters, and I don't see any benefits of 'encapsulation' here, literally no encapsulation.
But serialization frameworks requires that convention. Hibernate/Jacson and other are looking for methods that starts with get/is/set to read or set the value.
Private fields with getters and setters that do nothing other than get and set are totally pointless, you're right. It's the ability to interrupt the user's command and do something else before getting or before or after setting that makes them useful.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Since version 14, Java has the records
There is nor getters and setters, records has something called
accessor
(similar to getter, records are immutable).Anyway, many serialization frameworks (for example Jackson that serialize POJOs to JSON string) requires
JavaBeans
because of naming convention.And of course encapsulation stuff, but @andrew (he/him) already mentioned that in his comment.
What I see in code in 99% of cases, private fields and lombok getters/setters, and I don't see any benefits of 'encapsulation' here, literally no encapsulation.
But serialization frameworks requires that convention. Hibernate/Jacson and other are looking for methods that starts with
get
/is
/set
to read or set the value.As I know Hibernate does not always need getters.
But it is good point.
Private fields with getters and setters that do nothing other than get and set are totally pointless, you're right. It's the ability to interrupt the user's command and do something else before getting or before or after setting that makes them useful.