lombok简单的来讲就是在编译的时候,可以帮助我们生成getter与setter等方法,减少代码量。这可是一个好东西啊
1.eclipse安装lombok
java -jar lombok.jar
在出现画面点击specify location选择你的eclipse.exe即可
1.1 mac下配置eclipse安装法
1)将lombok集成到eclipse
2) lombok复制到Eclipse.app/Contents/Eclipse
3) 将如下内容添加到eclipse.ini尾部
-javaagent:../Eclipse/lombok.jar
-vmargs -javaagent:lombok.jar
重启eclipse
2.idea 安装lombok
idea通常在setting->plugins中搜索安装就可以了,如图:
示例代码:
package org.lyrk.accp8.s2.chapter.ch01; import lombok.AllArgsConstructor; import lombok.Cleanup; import lombok.Data; import lombok.SneakyThrows; import java.io.FileInputStream; import java.io.IOException; /** * Created by niechen on 17/4/17. */ @Data @AllArgsConstructor public class Dog { private int health; private int love; private int type; @SneakyThrows(IOException.class) public void display() { @Cleanup FileInputStream fileInputStream = new FileInputStream("test.txt"); } public Dog() { this.health = 60; this.love = 80; } public void play() { if (health < 60) { System.out.println("狗狗生病了,无法继续玩耍..."); } else { this.love += 2; this.health -= 5; System.out.println("狗狗很高兴"); } } }
瞬间代码清爽了...