E
E
Exito2018-07-19 22:30:45
Java
Exito, 2018-07-19 22:30:45

equals() method. Why is it not overridden for strings?

Hello everyone, please advise. By default, the equals() method looks like this:

public boolean equals(Object obj) {
        return (this == obj);
    }

In order to compare two objects of any class created by us, it is necessary to redefine the above method, since it compares the references, and not the objects themselves. But why is it not overridden when comparing strings?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Gornostaev, 2018-07-19
@Exito

Because the String class has a different default equals method .

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question