Sha*_*pci 4 java annotations code-readability getter-setter lombok
我经常在代码中看到以下注释:
@Getter
@Setter
public int test = 1;
Run Code Online (Sandbox Code Playgroud)
我知道我可以使用这个注释创建getter和setter使用方法.但是我需要使用哪些类/库来使用这些注释?
Jor*_*lla 11
@Getter并且@Setter是Lombook注释.
Lombook是产生重复类似的代码,一个框架equals,hashCode()或getters与setters在注释类或属性,清理代码,使得编码速度更快,避免了因忘记一些地方的人为错误...
请注意一件事:您的属性是公共的,插入getter和setter时没有多大意义:
@Getter
@Setter
private int test = 1;
Run Code Online (Sandbox Code Playgroud)
相当于:
private int test = 1;
public int getTest() {
return test;
}
public void setTest(int test) {
this.test = test;
}
Run Code Online (Sandbox Code Playgroud)
Eclipse/ 下载 jar并按照说明将它添加到你的项目中.NetBeans IntelliJ有它自己的插件由Michail Plushnikov:Maven
<dependencies>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.16.6</version>
<scope>provided</scope>
</dependency>
</dependencies>
Run Code Online (Sandbox Code Playgroud)其他仓库服务(Ivi,SBT,Graddle)点击这里
| 归档时间: |
|
| 查看次数: |
3043 次 |
| 最近记录: |