Lombok @EqualsAndHashCode Annotation

Lombok’s @ EqualsAndHashCode (lombok.EqualsAndHashCode) annotation.

Giving the class an @EqualsAndHashCode annotation properly overrides the equals and hashCode methods of the target class depending on the members in the class.

@EqualsAndHashCode without specifying a parameter will generate processing of equals, hashCode using all members in the class

import java.time.LocalDate;public class Person {	String firstName;	String lastName;	LocalDate dateOfBirth;		@Override	public int hashCode() {		final int prime = 31;		int result = 1;		result = prime * result + ((dateOfBirth == null) ? 0 : dateOfBirth.hashCode());		result = prime * result + ((firstName == null) ? 0 : firstName.hashCode());		result = prime * result + ((lastName == null) ? 0 : lastName.hashCode());		return result;	}	@Override	public boolean equals(Object obj) {		if (this == obj)			return true;		if (obj == null)			return false;		if (getClass() != obj.getClass())			return false;		Person other = (Person) obj;		if (dateOfBirth == null) {			if (other.dateOfBirth != null)				return false;		} else if (!dateOfBirth.equals(other.dateOfBirth))			return false;		if (firstName == null) {			if (other.firstName != null)				return false;		} else if (!firstName.equals(other.firstName))			return false;		if (lastName == null) {			if (other.lastName != null)				return false;		} else if (!lastName.equals(other.lastName))			return false;		return true;	}}

Using Lombok @EqualsAndHashCode  Annotation:

@EqualsAndHashCode public class PersonLombok {	String firstName;	String lastName;	LocalDate dateOfBirth;}