Yes, the default implementation is Object's (generally speaking; if you inherit from a class that redefined equals and/or hashCode, then you'll use that implementation instead).

From the documentation:

equals

The equals method for class Object implements the most discriminating possible equivalence relation on objects; that is, for any non-null reference values x and y, this method returns true if and only if x and y refer to the same object (x == y has the value true).

hashCode

As far as is reasonably practical, the hashCode method defined by class Object returns distinct integers for distinct objects. (This is typically implemented by converting the internal address of the object into an integer, but this implementation technique is not required by the JavaTM programming language.)

Answer from Etienne de Martel on Stack Overflow
🌐
Baeldung
baeldung.com › home › java › core java › java equals() and hashcode() contracts
Java equals() and hashCode() Contracts | Baeldung
January 8, 2024 - The default implementation of equals() in the Object class compares the identity of the object. In our example, the income and expenses instances of the Money class have two different identities.
🌐
Scaler
scaler.com › home › topics › java › what is equals() method in java?
What is equals() Method in Java? | Scaler Topics
January 8, 2024 - Since equals() is a method defined in the Object class thus the default implementation of the equals() method compares the object references or the memory location where the objects are stored in the heap.
🌐
Java Programming
java-programming.mooc.fi › part-8 › 3-similarity-of-objects
Similarity of objects - Java Programming
The equals method checks by default whether the object given as a parameter has the same reference as the object it is being compared to. In other words, the default behaviour checks whether the two objects are the same.
🌐
How to do in Java
howtodoinjava.com › home › java basics › java hashcode() and equals() methods
Java hashCode() and equals() Methods - HowToDoInJava
February 23, 2023 - It’s default implementation simply checks the object references of two objects to verify their equality. By default, two objects are equal if and only if they refer to the same memory location. Most Java classes override this method to provide ...
🌐
GeeksforGeeks
geeksforgeeks.org › java › equals-hashcode-methods-java
equals() and hashCode() methods in Java - GeeksforGeeks
July 23, 2025 - Deep Comparison: Suppose a class provides its own implementation of equals() method in order to compare the Objects of that class w.r.t state of the Objects. That means data members (i.e. fields) of Objects are to be compared with one another. Such Comparison based on data members is known as deep comparison. Syntax : public boolean equals (Object obj) // This method checks if some other Object // passed to it as an argument is equal to // the Object on which it is invoked.
🌐
Reddit
reddit.com › r/learnjava › override equals() when comparing objects - why is java designed this way?
r/learnjava on Reddit: Override equals() When Comparing Objects - Why is Java Designed This Way?
January 20, 2023 -

So, as a beginner, I found that comparing objects with the default equals() method actually does almost exactly the same thing like comparing them with ==. In other words, if two variables reference the same object, == will resolve as true and also equals() will resolve as true. But if we have two variables referencing two objects with a different identity but semantically the same (like, hmmm they look same to me! Same variables, etc.!) we actually have to come with our own equals() method and override the Java default method. (And when doing that, why not also override HashCode(), you know).

Now my question is not the typical "why???"(technicaly why it is needed?) but "why???" (why on earth was Java language designed this way)? Why Java does not have e.g. objectsEquals() method that would work for objects comparing all the fields etc. by default?

Why it even has equals() method that works the same as operator ==? In such a universe we could also have methods isTheSame(), isCompletelyTheSame() and thisIsEqual() all doing the same stuff? And also why we are even overriding it? Is it like "Java authors designed this method poorly or too generally, so let us made our better method that does also this and that". Why not create a framework class or our own class or just completely new method like sameObjects() and just use it with our own new beatiful name? Why overriding? Sorry, I am pretending rant, but I am just trying to be a little funny and also as a beginner I do not really understand this equals() override. What I am really trying to say is, I like to understand things deeply, in this case not only, it works basically in this and that way why but why it even exists as a part of our world:-)

🌐
Baeldung
baeldung.com › home › java › core java › overriding hashcode() and equals() for records
Overriding hashCode() And equals() For Records | Baeldung
January 16, 2024 - The default equals() implementation obeys the contract of the Object’s equals() method. Additionally, when we create a new record instance by copying all the attributes of another record instance, these two record instances must be equal.
Find elsewhere
🌐
Mistermicheels
learning-notes.mistermicheels.com › equals
Equals (Java) | learning-notes
By default, every Java object has an equals(Object o) method which is inherited from the Object class.
🌐
Upgrad
upgrad.com › home › tutorials › software & tech › equals method in java
Understanding the Equals () Method in Java: A Comprehensive Guide
4 weeks ago - By default, it compares the memory references of objects, but it can be overridden to provide custom comparison logic. The == operator, on the other hand, compares the memory addresses of objects and is used for reference equality testing.
Top answer
1 of 5
32

I'm going to answer your question with reservations, but you should know that you are hurting yourself if the intent of the question was to get you to learn and your solution was to ask StackOverflow. That aside...

This behavior is intentional.

The default equals() method on java.lang.Object compares memory addresses, which means that all objects are different from each other (only two references to the same object will return true).

java.lang.Integer overrides this to compare the value of the Integers, so two different Integers both representing the number two compare equal. If you used == instead, you would get false for both cases.

Standard practice in Java is to override the equals method to return true for objects which have the same logical value, even if they were created at different times (or even with different parameters). It's not very useful to have objects representing numbers if you don't have a way to ask, "do these two things represent the same value?".

Incidentally, and this is a tangent here, Java actually keeps a cache of Integer objects for small values. So sometimes you may get two Integer objects where even the == operator will return true, despite you getting them from two different sources. You can even get code that behaves differently for larger integers than it does for smaller, without having it look at the integral values!

2 of 5
7

This is intended behaviour.

Object.equals() considers the object identity (i.e. an object is only equal to itself), which is the only thing you can do for generic objects.

Integer overrides the method to depend on the integer value, since two Integer objects with the same value are logically equal. Many other classes also override equals() since it's a core mechanism of the standard API and a lot of functionaliy e.g. in the collections framework depends on it.

Why do are you puzzled by the behaviour anyway? Most people are only confused by the == operator not behaving like that (it works like Object.equals()).

🌐
Javapractices
javapractices.com › topic › TopicAction.do
Java Practices->Implementing equals
Implementing equals All objects have both identity (the object's location in memory) and state (the object's data). The == operator always compares identity. The default implementation of equals compares identity as well.
🌐
Test-king
test-king.com › blog › common-pitfalls-and-best-practices-for-overriding-equals-and-hashcode-in-java
overriding equals and hashCode best practices
This method is defined in the Object class and is inherited by all Java objects, as every class in Java ultimately inherits from the Object class. The default implementation of the equals() method in Java simply checks whether two object references point to the same memory location (reference ...
Top answer
1 of 4
8

The signature of Object.equals() is public boolean equals(Object). If you define a method public boolean equals(MyClass), you're adding a new method, with a different signature, instead of overriding (or redefining, if you prefer) the Object.equals() method.

Since all the collections call the Object.equals() method, your new method would never be called by anybody except your own code, and would thus be almost useless. For example, if you create a Set<MyClass>, it will consider that two instances are different, although your equals(MyClass) method considers them equal.

2 of 4
1

It is because most classes in Java (lists, queues, maps etc.) use the boolean equals(Object obj) method. At the time when Java was being designed way back in the nineties, Generics did not exist.

Comparison methods using for example the Comparator or Comparable, were updated to support generics, and thus take the right type (avoiding the instanceof) of your class directly. Object.equals() just takes a generic Object.

If you overload .equals() with new signatures, the other collections won't know about your new equals() methods and will still call the old original one provided by Object, so you have to stick with that and use instanceof. Remember overloading does not have the same effect of overriding. In overriding the subclass method gets called, since it has exactly the same signature. In overloading, you are just providing alternative functionality with a different signature, so the caller has to know about it.

Alternatively, instead of using the equals() method, maybe you can change your code a little to use the newer comparison methods with generics. Most collections have been updated to support Comparator, Comparable etc. with Generics too.

🌐
LabEx
labex.io › tutorials › java-how-to-implement-the-equals-method-in-java-classes-414077
How to implement the equals() method in Java classes | LabEx
It is a crucial method in ... The default implementation of the equals() method in the Object class compares the memory addresses of the two objects....
🌐
Software Testing Help
softwaretestinghelp.com › home › java › how to use .equals method in java – tutorial with examples
How To Use .equals Method In Java - Tutorial With Examples
April 1, 2025 - Answer: In Java, the ‘equals()’ method is a method of the Java Object class. This object class is the root of the class in Java. Hence, all Java classes by default inherit the equals () method from this root class.
🌐
Codefinity
codefinity.com › blog › How-equals()-and-hashCode()-Work-in-Java-and-Why-Following-Their-Contract-Matters
How equals() and hashCode() Work in Java and Why Following Their Contract Matters
The equals() method is used to check if two objects are equal. By default, the equals() method in the Object class compares objects by reference, meaning it returns true only if both objects point to the same memory location.
🌐
Thorben Janssen
thorben-janssen.com › ultimate-guide-to-implementing-equals-and-hashcode-with-hibernate
Ultimate Guide to Implementing equals() and hashCode() with Hibernate
October 14, 2022 - Otherwise, 2 different instances of your primary key object, that have the same attribute values, would be equal in the database but not in your Java code. That would obviously create a lot of problems, but it doesn’t answer the question if you need to implement these methods for your entity classes. The Object class already provides a default implementation of these methods.