Lombok @Value Annotation

@Value is the immutable variant of @Data; all fields are made private and final by default, and setters are not generated. The class itself is also made final by default, because immutability is not something that can be forced onto a subclass. Like @Data, useful toString(), equals() and hashCode() methods are also generated, each field gets a getter method, and a constructor that covers every argument (except final fields that are initialized in the field declaration) is also generated.

Code with Lombok @Value Annotation

import lombok.Value;@Valuepublic class Person1 {    private long id;    private String name;}

Net Java

 

public final class Person1 {    private final long id;    private final String name;    public Person1(final long id, final String name) {        this.id = id;        this.name = name;    }    public long getId() {        return this.id;    }    public String getName() {        return this.name;    }    @Override    public boolean equals(final Object o) {        if (o == this) return true;        if (!(o instanceof Person1)) return false;        final Person1 other = (Person1) o;        if (this.getId() != other.getId()) return false;        final Object this$name = this.getName();        final Object other$name = other.getName();        if (this$name == null ? other$name != null : !this$name.equals(other$name)) return false;        return true;    }    @Override    public int hashCode() {        final int PRIME = 59;        int result = 1;        final long $id = this.getId();        result = result * PRIME + (int) ($id >>> 32 ^ $id);        final Object $name = this.getName();        result = result * PRIME + ($name == null ? 43 : $name.hashCode());        return result;    }    @Override    public String toString() {        return "Person1(id=" + this.getId() + ", name=" + this.getName() + ")";    }}