Lombok Maven与Eclipse或STS中的Lombok不同

时间:2018-07-20 08:58:57

标签: java eclipse lombok

我在Maven编译和Eclipse编译之间有差值。用Maven可以,但不能用Eclipse。

在Eclipse进行编译时,它会丢失具有两个参数的构造函数上的@ConstructorProperties({ "id", "profile" })注释。

我的Java文件:

@Data
@AllArgsConstructor
public class Author {
    private String id;
    private String profile;
}

Maven的完整课程(确定):

import java.beans.ConstructorProperties;

public class Author {
    private String id;
    private String profile;

    public void setId(String id) {
        this.id = id;
    }

    public void setProfile(String profile) {
        this.profile = profile;
    }

    @Override
    public boolean equals(Object o) {
        if (o == this) {
            return true;
        }
        if (!(o instanceof Author)) {
            return false;
        }
        final Author other = (Author) o;
        if (!other.canEqual(this)) {
            return false;
        }
        final Object this$id = getId();
        final Object other$id = other.getId();
        if (this$id == null ? other$id != null : !this$id.equals(other$id)) {
            return false;
        }
        final Object this$profile = getProfile();
        final Object other$profile = other.getProfile();
        return this$profile == null ? other$profile == null : this$profile.equals(other$profile);
    }

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

    @Override
    public int hashCode() {
        final int PRIME = 59;
        int result = 1;
        final Object $id = getId();
        result = result * 59 + ($id == null ? 43 : $id.hashCode());
        final Object $profile = getProfile();
        result = result * 59 + ($profile == null ? 43 : $profile.hashCode());
        return result;
    }

    @Override
    public String toString() {
        return "Author(id=" + getId() + ", profile=" + getProfile() + ")";
    }

    @ConstructorProperties({ "id", "profile" })
    public Author(String id, String profile) {
        this.id = id;
        this.profile = profile;
    }

    public String getId() {
        return id;
    }

    public String getProfile() {
        return profile;
    }
}

Eclipse的完整类:

public class Author {
    private String id;
    private String profile;

    public String getId() {
        return id;
    }

    public String getProfile() {
        return profile;
    }

    public void setId(String id) {
        this.id = id;
    }

    public void setProfile(String profile) {
        this.profile = profile;
    }

    @Override
    public boolean equals(Object o) {
        if (o == this) {
            return true;
        }
        if (!(o instanceof Author)) {
            return false;
        }
        final Author other = (Author) o;
        if (!other.canEqual(this)) {
            return false;
        }
        final Object this$id = getId();
        final Object other$id = other.getId();
        if (this$id == null ? other$id != null : !this$id.equals(other$id)) {
            return false;
        }
        final Object this$profile = getProfile();
        final Object other$profile = other.getProfile();
        return this$profile == null ? other$profile == null : this$profile.equals(other$profile);
    }

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

    @Override
    public int hashCode() {
        final int PRIME = 59;
        int result = 1;
        final Object $id = getId();
        result = result * 59 + ($id == null ? 43 : $id.hashCode());
        final Object $profile = getProfile();
        result = result * 59 + ($profile == null ? 43 : $profile.hashCode());
        return result;
    }

    @Override
    public String toString() {
        return "Author(id=" + getId() + ", profile=" + getProfile() + ")";
    }

    public Author(String id, String profile) {
        this.id = id;
        this.profile = profile;
    }
}

1 个答案:

答案 0 :(得分:0)

@tobias_k查找解决方案:

Eclipse需要安装与Maven项目使用的版本相同的Lombok。