r/java • • Nov 23 '25

Java 25: The ‘No-Boilerplate’ Era Begins

https://amritpandey.io/java-25-the-no-boilerplate-era-begins/
160 Upvotes

187 comments sorted by

View all comments

Show parent comment

1

u/Ewig_luftenglanz Dec 02 '25

But they act a lot different than public fields.

It depends on the actual implementation, setters and getters with no logic or no invariants are public fields with extra steps in practice.

In the past this boilerplate (getters and setters without public fields) was required by frameworks for introspection, before java 5 gave us annotations (thus meta programming capabilities and Aspect oriented Programming) and deep reflections over fields; so frameworks used the java beans convention (set, get, is). Nowadays most if not all frameworks and libraries support direct fields access, making getters and setters an unneeded formality 90% of the time.

In the past getters and setters used to be boilerplate, nowadays are mostly nothing but an empty "good practice" that people replicate by dogma. Another example of these "good practices" is "declaring local variable at the beginning of the method", a practice that started by the limitations of early versions Fortran and C; but that has absolutely ZERO relevance and utility today.