有没有一种方法可以重命名用Lombok生成的Getter方法?
我正在尝试弄清楚是否有一种方法可以使用Lombok手动设置Getter
方法名称。考虑以下示例:
@Getter
@Builder(setterPrefix = "with")
@AllArgsConstructor(access = AccessLevel.PRIVATE)
public class Context {
@Builder.Default
private final boolean logReceivedMessages = false;
... many other fields ...
}
使用上面的示例,您可以这样构建上下文:
context = Context.builder().withLogReceivedMessages(true/false).build;
然后将其用作
if(context.isLogReceivedMessages()) {
XYZ
} else {
zyx
}
生成方法的名称并不是我该如何说出它,并且想知道是否有一种自定义的方法?是否有注释可以让我将其命名为shopslogreceivedMessages()
而不是iSlogreCeivedMessages
?我似乎在文档中找不到。
I'm trying to figure out if there is a way to set the getter
method name manually using lombok. Consider the following example:
@Getter
@Builder(setterPrefix = "with")
@AllArgsConstructor(access = AccessLevel.PRIVATE)
public class Context {
@Builder.Default
private final boolean logReceivedMessages = false;
... many other fields ...
}
With the above example you are able to build the context like so:
context = Context.builder().withLogReceivedMessages(true/false).build;
and then use it as
if(context.isLogReceivedMessages()) {
XYZ
} else {
zyx
}
The name of the generated method is not really how I would word it and was wondering if there was a way to customize it? Is there an annotation which would allow me to name it to something like shouldLogReceivedMessages()
instead of isLogReceivedMessages
? I can't seem to find that in the docs.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果这是需要更改名称的唯一方法,我建议您在
上下文
中添加另一个getter;它将覆盖Lombok的Getter。但是,如果您需要以不同的方法自定义的更多自定义,请参考Teddy提到的帖子。
If this is the only method which needs name change, I would suggest to add another getter by your own inside
Context
; it will override lombok's getter.But if you need lot more customisation in different methods then refer SO post mentioned by Teddy.