英文:
Lombok won't generate getter methods for variables when annotation is in class level
问题
当注解位于类级别时,它不会为变量创建getter方法:
@Getter
public class Config {
private static final String TEST = "";
}
但如果将注解放在变量级别,它会创建getter方法:
public class Config {
@Getter
private static final String TEST = "";
}
英文:
I'm quite confused as to why the annotation won't create getter methods for the variables if the annotation is at class level
@Getter
public class Config {
private static final String TEST = "";
}
But creates the getters if annotation is at the variable level.
public class Config {
@Getter
private static final String TEST = "";
}
Thank you!
答案1
得分: 2
你可以按照文档所示来完成这个操作:
> 你可以为一个类添加@Getter或@Setter注解。这样做等同于为该类中的所有非静态字段添加该注解。字段上的@Getter/@Setter注解优先于类上的注解。
你所遇到的问题是因为你遇到的字段是static
。
英文:
You can do this as the documentation says:
> You can annotate a class with a @Getter or @Setter annotation. Doing so is equivalent to annotating all non-static fields in that class with that annotation. @Getter/@Setter annotations on fields take precedence over the ones on classes.
The problem you're seeing is because the field you're having problems with is static
.
答案2
得分: 1
问题是Class
级别的Getter
注解在处理Static
字段时不起作用。请查看Lombok文档这里。请参考下面的屏幕截图 --
英文:
The problem is Class
level Getter
annotation doesn't work with Static
fields. Check the Lombok documentation here. Please refer to the screenshot below --
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论