我经常在代码中看到以下注释:
@Getter
@Setter
public int test = 1;
我知道我可以创建getter
和setter
使用这个注释的方法。但是我需要使用哪些类/库这些注释?
@Getter
和@Setter
是龙目岛注释。
龙目岛是产生重复类似的代码,一个框架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
/下载jar,请按照说明将其添加到您的项目中。NetBeans
IntelliJ
有它自己的插件由米凯尔Plushnikov:Maven
<dependencies>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.16.6</version>
<scope>provided</scope>
</dependency>
</dependencies>
其他仓库服务(Ivi
,SBT
,Graddle
)在这里查看
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句