I'm failing the 2nd last requirement, but I am not sure why. The task description says that the main method isn't tested, so I don't know how to go about passing this test. I'm getting the correct answer as far as I can tell. I'm just spinning in circles trying to solve this.
package com.codegym.task.task21.task2105;
import java.util.HashSet;
import java.util.Set;
/*
Fix the bug. Comparing objects
*/
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 (o == this) {
return true;
}
if (o == null) {
return false;
}
if (!(o instanceof Solution)) {
return false;
}
Solution n = (Solution) o;
return (n.first == this.first) && (n.last == this.last);
}
@Override
public int hashCode() {
return this.first.length() + this.last.length();
}
public static void main(String[] args) {
Set<Solution> s = new HashSet<>();
s.add(new Solution("Mickey", "Mouse"));
System.out.println(s.contains(new Solution("Mickey", "Mouse")));
}
}