1. 程式人生 > 其它 >java開發神器Lombok初識

java開發神器Lombok初識

一、前言

  在我們使用java語言定義實體物件的時候,以前經常需要寫set和get方法,會覺得很繁瑣。偶然接觸到一款神器叫Lombok的,可以幫我們很好的解決這種瑣事。

二、步驟

  1、在idea上安裝Lombok外掛

  File-Settings-Plugins,搜尋Lombok

  

  下載後,需要重啟idea生效

  2、在pom檔案新增相關依賴

        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>
lombok</artifactId> <version>1.18.20</version> <scope>provided</scope> </dependency>

三、測試類

import lombok.Data;

@Data
public class Text {

    private String content;
}

idea編譯之後的:

//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler) // package restassureddemo.weixin; public class Text { private String content; public Text() { } public String getContent() { return this.content; } public void setContent(String content) { this.content = content; }
public boolean equals(Object o) { if (o == this) { return true; } else if (!(o instanceof Text)) { return false; } else { Text other = (Text)o; if (!other.canEqual(this)) { return false; } else { Object this$content = this.getContent(); Object other$content = other.getContent(); if (this$content == null) { if (other$content != null) { return false; } } else if (!this$content.equals(other$content)) { return false; } return true; } } } protected boolean canEqual(Object other) { return other instanceof Text; } public int hashCode() { int PRIME = true; int result = 1; Object $content = this.getContent(); int result = result * 59 + ($content == null ? 43 : $content.hashCode()); return result; } public String toString() { return "Text(content=" + this.getContent() + ")"; } }

  說明生效