Why isn't the 4th requirement validating?
package com.codegym.task.task21.task2105;
import java.util.HashSet;
import java.util.Set;
import java.util.Objects;
/*
Fix the bug. Comparing objects
*/
public class Solution {
private final String first, last;
public Solution(String first, String last) {
this.first = first;
this.last = last;
}
public boolean equals(Object o) {
if (o == this) return true;
if (o == null) return false;
if (!(o instanceof Solution)) return false;
Solution n = (Solution) o;
return this.hashCode() == n.hashCode();
}
public int hashCode() {
if (this.first == null) {
if (this.last == null) {
return 0;
} else {
return this.last.hashCode();
}
} else {
if (this.last == null) {
return this.first.hashCode();
} else {
return this.first.hashCode() + this.last.hashCode();
}
}
}
public static void main(String[] args) {
Set<Solution> s = new HashSet<>();
s.add(new Solution("Mickey", "Mouse"));
System.out.println(s.contains(new Solution("Mickey", "Mouse")));
}
}