[英]Can anyone tell how can i put getter and setter on the below code, and what exactly getter and setter do
[英]How can I get @getter and @setter?
我经常在代码中看到如下注解:
@Getter
@Setter
public int test = 1;
我知道我可以使用此注释创建getter
和setter
方法。 但是我需要使用哪些类/库来使用这些注释?
@Getter
和@Setter
是Lombok注释。
Lombok是一个框架,它在带注释的类或属性中生成重复的代码,如equals
、 hashCode()
或getters
和setters
,清理代码,使编码更快,避免由于忘记某些部分而导致的人为错误......
请注意一件事:您的属性是 public ,插入 getter 和 setter 时没有多大意义:
@Getter
@Setter
private int test = 1;
相当于:
private int test = 1;
public int getTest() {
return test;
}
public void setTest(int test) {
this.test = test;
}
Eclipse
/ NetBeans
在此处下载jar 并按照说明将其添加到您的项目中。IntelliJ
有自己的插件Michail Plushnikov : Maven
<dependencies> <dependency> <groupId>org.projectlombok</groupId> <artifactId>lombok</artifactId> <version>1.16.6</version> <scope>provided</scope> </dependency> </dependencies>
其他存储库服务( Ivi
、 SBT
、 Graddle
)在此处查看
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.