accessors 作用_@Accessors介绍配置getter和setter

本文介绍了@Accessors注解在Java编程中的作用,主要用于配置getter和setter方法的生成方式。该注解包含三个属性:fluent(是否创建流畅API,即方法名不带get/set且setter返回this),chain(setter是否返回this以支持链式调用)和prefix(忽略特定字段前缀)。通过调整这些属性,开发者可以自定义存取器的生成规则。
摘要由CSDN通过智能技术生成

前言

今天在看GitHub某大神写的代码的时候看到一个标签并没有使用过,所有百度了一下使用方法在此记录一下。

@Accessors

Accessor的中文含义是存取器,@Accessors用于配置getter和setter方法的生成结果。

源代码:

@Target({ElementType.TYPE, ElementType.FIELD})

@Retention(RetentionPolicy.SOURCE)

public @interface Accessors {

/**

* If true, accessors will be named after the field and not include a {@code get} or {@code set}

* prefix. If true and {@code chain} is omitted, {@code chain} defaults to {@code true}.

* default: false

*

* @return Whether or not to make fluent methods (named {@code fieldName()}, not for example {@code setFieldName}).

*/

boolean fluent() default false;

/**

* If true, setters return {@code this} instead of {@code void}.

* default: false,

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值