为什么它没有到达“这里”的打印行?换句话说,为什么它不使用我覆盖的等于?提前致谢
import java.util.*;
class NumberClass extends Object{
private int number;
public NumberClass(int n){
number=n;
}
@Override
public boolean equals(Object other){
System.out.println("here");
return false;
}
@Override
public String toString(){
return number+"";
}
}
public class HelloWorld {
public static void main(String[] args) {
Set <NumberClass> set= new HashSet<NumberClass>();
set.add(new NumberClass(0));
set.add(new NumberClass(0));
System.out.println(set);
}
}