Hello. Help please solve the problem. Wrote a class. I want to override the equals () and hashCode () methods. I trust to generate the IDEA code, she does it, but generates it, but for herself it is non-working.
public final class ComplexNumber { private final double re; private final double im; public ComplexNumber(double re, double im) { this.re = re; this.im = im; } public double getRe() { return re; } @Override public boolean equals(Object o) { if (this == o) return true; //(this == o) - ругается if (o == null || getClass() != o.getClass()) return false; //ругается getClass() != o.getClass() ComplexNumber that = (ComplexNumber) o; //(ComplexNumber) o - ругается if (Double.compare(that.re, re) != 0) return false; if (Double.compare(that.im, im) != 0) return false; return true; } @Override public int hashCode() { int result; long temp; temp = Double.doubleToLongBits(re); result = (int) (temp ^ (temp >>> 32)); temp = Double.doubleToLongBits(im); result = 31 * result + (int) (temp ^ (temp >>> 32)); return result; } public double getIm() { return im; } public static void main(String[] args) { ComplexNumber a = new ComplexNumber(1, 1); ComplexNumber b = new ComplexNumber(1, 1); System.out.println(a.equals(b)); System.out.println(a.hashCode() + " " + a.hashCode()); }} Errors:
Error:(19, 5) java: method does not override or implement a method from a supertype Error:(21, 18) java: incomparable types: ComplexNumber and Object Error:(22, 37) java: incomparable types: java.lang.Class<capture#1 of ? extends ComplexNumber> and java.lang.Class<capture#2 of ? extends Object> Error:(24, 46) java: incompatible types: Object cannot be converted to ComplexNumber Tell me please, what's the problem with the generated code?