add equals method

This commit is contained in:
sharifi 2020-11-12 14:06:53 +03:30
parent 937f0fb784
commit d0678c77ab
1 changed files with 11 additions and 0 deletions

View File

@ -1,6 +1,7 @@
package com.baeldung.crypto;
import java.io.Serializable;
import java.util.Objects;
public class Student implements Serializable {
private String name;
@ -26,4 +27,14 @@ public class Student implements Serializable {
public void setAge(int age) {
this.age = age;
}
@Override
public boolean equals(Object o) {
if (this == o)
return true;
if (o == null || getClass() != o.getClass())
return false;
Student student = (Student) o;
return age == student.age && Objects.equals(name, student.name);
}
}