Перепробовал всё, читал статьи и смотрел решения других. Ничего не помогает, что здесь не так?
package com.javarush.task.task21.task2104;
import java.util.HashSet;
import java.util.Objects;
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.getClass() != this.getClass()) return false;
if (!(o instanceof Solution)) return false;
Solution solution = (Solution) o;
boolean result = true;
if (this.first == null){
return solution.first == null;
}
if (solution.first == null){
return false;
}
if (this.last == null){
return solution.last == null;
}
if (solution.last == null){
return false;
}
if (!this.first.equals(solution.first)){result = false;}
if (!this.last.equals(solution.last)){result = false;}
return result;
}
@Override
public int hashCode() {
return Objects.hash(first, last);
}
public static void main(String[] args) {
Set<Solution> s = new HashSet<>();
s.add(new Solution(null, "1"));
System.out.println(s.contains(new Solution("1", null)));
}
}