简体   繁体   中英

@Override public boolean equals(Object o) “Method does not override and superclass method”

Theoretically this is a really simple (dumb) question...

Compiles successfully:

@Override
public int hashCode() {return 0;}

Error: "Method does not override any superclass method"

@Override
public boolean equals(Object obj) {return true;}

It seems to me that if my override of hashCode() compiles the override of equals() should also compile... Obviously I don't understand something relatively fundamental...

What should I look for to resolve this compiler error?

My project had a class within the same package as the class exhibiting the compilations issue... this obscured the Java's base Object class (and its equals() method).

Here's the corrected code:

@Override
public boolean equals(java.lang.Object obj)
{
    return true;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM