---
title: Override Both Equals And Hashcode
description: "**Impact area** Manageability **Severity** Medium **Affected element** Apex Class ## Rule ID SF-OVERRIDE-BOTH ## Impact Override equals() and not override hashCode() can result in unexpected behavior when your class is in conjunction with all hash-based collections. Remediation You must override…"
url: "https://community-staging.qualityclouds.com/qcdocs/qcr/rules/override-both-equals-and-hashcode/"
updated: "2025-03-21"
category: PMD Rules
---

# Override Both Equals And Hashcode

**Impact area**

Manageability

**Severity**

Medium

**Affected element**

Apex Class

## Rule ID

SF-OVERRIDE-BOTH

## Impact

Override equals() and not override hashCode() can result in unexpected behavior when your class is in conjunction with all hash-based collections.

Remediation

You must override hashCode() in every class that overrides equals().

### Time to fix

30 min

## References

This rule is linked to [OverrideBothEqualsAndHashcode](http://you%20must%20override%20hashcode%28%29%20in%20every%20class%20that%20overrides%20equals%28%29./)
