From f5380f98f6f73caaeb616c620d36ba72ebdcfdda Mon Sep 17 00:00:00 2001 From: Loredana Crusoveanu Date: Wed, 11 May 2022 12:52:41 +0300 Subject: [PATCH] BAEL-5420 fix equals method --- .../main/java/com/baeldung/employee/EmployeeVO.java | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/core-java-modules/core-java-lang-4/src/main/java/com/baeldung/employee/EmployeeVO.java b/core-java-modules/core-java-lang-4/src/main/java/com/baeldung/employee/EmployeeVO.java index 7a1775f79d..3d2c61aa3d 100644 --- a/core-java-modules/core-java-lang-4/src/main/java/com/baeldung/employee/EmployeeVO.java +++ b/core-java-modules/core-java-lang-4/src/main/java/com/baeldung/employee/EmployeeVO.java @@ -28,9 +28,15 @@ public class EmployeeVO { @Override public boolean equals(Object obj) { - return Objects.equals(firstName, this.firstName) - && Objects.equals(lastName, this.lastName) - && Objects.equals(startDate, this.startDate); + + if (this == obj) return true; + if (obj == null || getClass() != obj.getClass()) return false; + + EmployeeVO emp = (EmployeeVO) obj; + + return Objects.equals(firstName, emp.firstName) + && Objects.equals(lastName, emp.lastName) + && Objects.equals(startDate, emp.startDate); } @Override