Understanding Lombok @Accessors Annotation: fluent, chain, and prefix attributes

This article explains the Lombok @Accessors annotation, detailing its source code, the meaning of its fluent, chain, and prefix attributes, and demonstrates how these settings affect generated getter and setter methods, while also providing usage examples and related promotional links.

Top Architect
Top Architect
Top Architect
Understanding Lombok @Accessors Annotation: fluent, chain, and prefix attributes

Preface

In your work you may encounter the annotation @Accessors(chain = true) from the Lombok library and wonder what it does.

1. @Accessors source code

Opening the source of @Accessors reveals:

1) The annotation mainly controls how getter and setter methods are generated for fields.

2) When applied to a class, it affects all fields; when applied to a specific field, it only affects that field.

2. @Accessors attribute description

2.1 fluent attribute

If set to true, the generated getter does not have the get prefix and the setter does not have the set prefix.

2.2 chain attribute

If set to true, the setter returns the current object, enabling method chaining.

2.3 prefix attribute

This attribute is a string array; when it contains values, those prefixes are ignored when generating getter and setter names.

@Accessors(fluent = true, chain = true, prefix = {"m_", "_"})

The article also includes several illustrative images and promotional sections inviting readers to join a WeChat group, claim a gift package, and explore additional resources.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

BackendjavaLombokAccessorsFluentAPI
Top Architect
Written by

Top Architect

Top Architect focuses on sharing practical architecture knowledge, covering enterprise, system, website, large‑scale distributed, and high‑availability architectures, plus architecture adjustments using internet technologies. We welcome idea‑driven, sharing‑oriented architects to exchange and learn together.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.