Тестирование проходит верно, валидатор не принимает
package com.javarush.task.task21.task2104;
import java.util.HashSet;
import java.util.Set;
/*
Equals and HashCode
*/
public class Solution {
private final String first, last;
public Solution(String first, String last) {
this.first = first;
this.last = last;
}
public boolean equals(Object obj) {
if (this == obj) return true;
if (obj == null) return false;
if (!(obj instanceof Solution)) return false;
Solution sol = (Solution) obj;
if (sol.first == null && this.first == null && sol.last == null && this.last == null) return true;
if (sol.first == null && this.first == null && sol.last == this.last) return true;
if (sol.first == this.first && sol.last == null && this.last == null) return true;
if (sol.first == this.first && sol.last == this.last) return true;
return true;
}
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((first == null) ? 0 : first.hashCode()) + ((last == null) ? 0 : last.hashCode());
return result;
}
public static void main(String[] args) {
Set<Solution> s = new HashSet<>();
s.add(new Solution("Donald", "Duck"));
System.out.println(s.contains(new Solution("Donald", "Duck")));
}
}