Добрый день, валидатор не принимает решение, подскажите, что не учел?
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(Solution n) {
if (n == null || n.getClass()!=this.getClass()) return false;
if (!(n instanceof Solution))
return false;
if (this == n) return true;
Solution sol = (Solution)n;
boolean fitstBool = (this.first!=null && sol.first!=null) && (this.first == sol.first)||(this.first.equals(sol.first));
boolean lastBool = (this.last!=null && sol.last!=null)&& (this.last == sol.last)||(this.last.equals(sol.last));
return fitstBool && lastBool;
}
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")));
}
}