Не проходит валидацию.
package com.javarush.task.task21.task2104;
import java.util.HashMap;
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;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || ! (o instanceof Solution)) return false;
Solution solution = (Solution) o;
return first == solution.first || (first != null && first.equals(solution.first)) &&
last == solution.last || (last != null && last.equals(solution.last));
}
public int hashCode(){
int h1 = 0;
if (first != null) h1 += first.hashCode() * 31;
if (last != null) h1 += last.hashCode();
return h1;
}
public static void main(String[] args) {
Set<Solution> s = new HashSet<>();
Solution solution = new Solution("Donald", null);
s.add(solution);
System.out.println(solution. hashCode());
Solution solution1 = new Solution(null, "Dack");
System.out.println(solution1.hashCode());
System.out.println(solution.equals(solution1));
System.out.println(s.contains(solution));
}
}