<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; } public boolean equals(Solution n) { if (this == n){ return true; } if ( n instanceof Solution){ return true; } return n.first!=null && n.last!=null && this.first.equals(n.first)&& this.last.equals(n.last); } public int hashCode() { int result = first != null ? first.hashCode() : 0; result = 31 * result + (last != null ? last.hashCode() : 0); 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"))); } } >