eclipse環境下lombok中的註解失效 @AllArgsConstructor @Slf4j 註解失效

qq_38632641發表於2018-05-15

安裝
1.下載 lombok.jar
2.官網說是可以雙擊安裝,,,我用這種方法不可行
2.手動安裝
(1)將lombok.jar移到eclipse的安裝目錄
這裡寫圖片描述

(2)在eclipse.in檔案最後加入下面兩行

-Xbootclasspath/a:lombok.jar
-javaagent:lombok.jar
  • 1
  • 2

=============
-javaagent:xxx.jar 的jar名稱 需要與根目錄下的jar名一致,
不一致,可能會出現eclipse無法啟動的情況。

(3)重啟eclipse,進行程式碼測試

原始java程式碼:

public class NoteTest {

    private int noteId;
    private String title;
    private String content;
    private int typeId;

}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8

class檔案反編譯後:

public class NoteTest
{

    private int noteId;
    private String title;
    private String content;
    private int typeId;

    public NoteTest()
    {
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11

、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、
加入lombok註解後的java程式碼:

@Data
@NoArgsConstructor
@AllArgsConstructor
@ToString(exclude="typeId")
public class NoteTest {

    private int noteId;
    private String title;
    private String content;
    private int typeId;

}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12

加註解,經反編譯:

public class NoteTest
{

    private int noteId;
    private String title;
    private String content;
    private int typeId;

    public int getNoteId()
    {
        return noteId;
    }

    public String getTitle()
    {
        return title;
    }

    public String getContent()
    {
        return content;
    }

    public int getTypeId()
    {
        return typeId;
    }

    public void setNoteId(int noteId)
    {
        this.noteId = noteId;
    }

    public void setTitle(String title)
    {
        this.title = title;
    }

    public void setContent(String content)
    {
        this.content = content;
    }

    public void setTypeId(int typeId)
    {
        this.typeId = typeId;
    }

    public boolean equals(Object o)
    {
        if (o == this)
            return true;
        if (!(o instanceof NoteTest))
            return false;
        NoteTest other = (NoteTest)o;
        if (!other.canEqual(this))
            return false;
        if (getNoteId() != other.getNoteId())
            return false;
        Object this$title = getTitle();
        Object other$title = other.getTitle();
        if (this$title != null ? !this$title.equals(other$title) : other$title != null)
            return false;
        Object this$content = getContent();
        Object other$content = other.getContent();
        if (this$content != null ? !this$content.equals(other$content) : other$content != null)
            return false;
        return getTypeId() == other.getTypeId();
    }

    protected boolean canEqual(Object other)
    {
        return other instanceof NoteTest;
    }

    public int hashCode()
    {
        int PRIME = 59;
        int result = 1;
        result = result * 59 + getNoteId();
        Object $title = getTitle();
        result = result * 59 + ($title != null ? $title.hashCode() : 43);
        Object $content = getContent();
        result = result * 59 + ($content != null ? $content.hashCode() : 43);
        result = result * 59 + getTypeId();
        return result;
    }

    public NoteTest()
    {
    }

    public NoteTest(int noteId, String title, String content, int typeId)
    {
        this.noteId = noteId;
        this.title = title;
        this.content = content;
        this.typeId = typeId;
    }

    public String toString()
    {
        return (new StringBuilder("NoteTest(noteId=")).append(getNoteId()).append(", title=").append(getTitle()).append(", content=").append(getContent()).append(")").toString();
    }
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84
  • 85
  • 86
  • 87
  • 88
  • 89
  • 90
  • 91
  • 92
  • 93
  • 94
  • 95
  • 96
  • 97
  • 98
  • 99
  • 100
  • 101
  • 102
  • 103
  • 104
  • 105

相關文章