Why Java Developers Prefer Lombok Over Public Fields: Dogmatism's Toll
This article argues that Java developers adopt Lombok as a compromise against dogmatic encapsulation that mandates getters/setters for fields rarely needing custom logic, while also criticizing unnecessary interface/impl splits and DTO naming conventions, illustrated by a case where a getter enabled quick refactoring across hundreds of call sites.
The author contends that most Java developers would rather make fields public, which is a valid desire, but are forced into using Lombok by pervasive dogmatism and formalism in the Java ecosystem.
What Is Dogmatism?
Originally, the idea was that in some scenarios a field's implementation might need to change to accommodate new requirements, so accessing it via a method (getter/setter) is safer than direct field access. Dogmatism turns this into a universal rule: always use methods, regardless of context or actual need.
The result: 99.99% of fields never have a non-default implementation, yet every field gets wrapped in a method. Writing those methods is tedious, so developers use Lombok to generate the boilerplate and "paper over" the problem.
Other Dogmatic Patterns
Service interface/impl split: Services are routinely split into an interface (xxx) and an implementation (xxxImpl), even though 99.99% of services have no second implementation and the project does not use an RPC framework (e.g., Dubbo) that requires interfaces for proxying.
Misapplied DTO/BO/PO naming: To signal a domain model, many projects add suffixes like BO, PO, DTO, etc., but they misunderstand domain-driven design — which is about aggregating related domain concepts — and instead dump unrelated DTOs into a single dto package.
The Java Ecosystem's Dogma Problem
The Java ecosystem is described as a collection of dogmatic "best practices" spanning code style, design patterns, and Spring framework usage. These practices often over-engineer small problems and create more issues than they solve.
Concrete Example: The expressNo Field
A field expressNo (tracking number) was accessed via getter in hundreds of places. Later, a requirement emerged to support parent-child parcels: determining whether two tracking numbers belong to the same parent-child group required extracting a substring from the tracking number. Without a getter, modifying hundreds of call sites would have been infeasible. With the getter, the change was confined to the getter method and took under two minutes. The author emphasizes that this is exactly the scenario where a getter proves invaluable; had the field been public, the refactoring would have been a nightmare.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
