我有这个代码:
@Override
public boolean equals(Object obj) {
System.out.println("equals called");
if(this == obj) {
System.out.println("THIS object is the same as OBJ");
return true;
}
System.out.println("obj.getClass() is " + obj.getClass());
System.out.println("this.getClass() is " + this.getClass());
if ((obj == null) || (obj.getClass() != this.getClass())) {
return false;
}
double objOrbitalPeriod = ((HeavenlyBody) obj).getOrbitalPeriod();
return this.orbitalPeriod == objOrbitalPeriod;
}
@Override
public int hashCode() {
return 0;
}
Run Code Online (Sandbox Code Playgroud)
在主要代码是:
private static Set<Planet> solarSystem = new HashSet<>();
public static void main(String[] args) {
Planet planet = …Run Code Online (Sandbox Code Playgroud)