equals method

The method that decides whether two objects hold the same value, as opposed to == which checks whether they are the same object.

In more detail

The default equals inherited from Object only checks identity, so classes that represent values override it. Records generate equals for you by comparing every component. Whenever equals is overridden, hashCode must be overridden to match.

Example

first.equals(second)  // true for two Point(2, 3) records

Related terms

Taught in

References

Certification courses