Skip to content

Checking your reading list…

Retry verification

Stay curious. Build better.

Appearance

Choose how BestHub looks on this device.

Changes apply immediately.

Search articles

Open Discover with these filters

Suggested searches

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

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.

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.

About this article

For questions about attribution, corrections or content rights, please contactadmin@besthub.devand we will review it promptly.

Report an issue with this article
BackendJavaLombokAccessorsFluentAPI

Reader feedback

Was this useful?

Useful0

Discussion 0

Questions, practical examples and thoughtful responses.

Open full discussion