D
D
Dmitry072016-08-21 10:42:35
Java
Dmitry07, 2016-08-21 10:42:35

What is the point of checking getClass() != o.getClass()?

Good day.
There is an example implementation of the equals() method:

public boolean equals(Object o) {
    if (this == o) return true;
    if (o == null || getClass() != o.getClass()) return false;
    Vertex vertex = (Vertex) o;
    return Objects.equals(getId(), vertex.getId()) &&
        getState() == vertex.getState() &&
        Objects.equals(getVertices(), vertex.getVertices());
}

The question arises, what is the specific essence of this check?
getClass() != o.getClass()
Thanks to.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question