有没有一种方法可以重命名用Lombok生成的Getter方法?

发布于 2025-02-07 11:26:14 字数 732 浏览 1 评论 0原文

我正在尝试弄清楚是否有一种方法可以使用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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

怎樣才叫好 2025-02-14 11:26:14

如果这是需要更改名称的唯一方法,我建议您在上下文中添加另一个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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文