# Why Java hashCode and equals implementations must satisfy the contract

DevFeed: [Why Java hashCode and equals implementations must satisfy the contract](<https://devfeed.tech/articles/consistent-return-of-hashcode-in-java-27260.md>)

Original publisher: [Read original article](<https://blog.pchudzik.com/201610/changing-hashcode/>)

Published: 2016-10-19T00:00:00Z

Content type: tutorial

Language: en

Sources: [Paweł Chudzik](<https://devfeed.tech/sources/pawe-chudzik.md>)

Topics: [Java](<https://devfeed.tech/topics/java.md>), [hash](<https://devfeed.tech/topics/hash.md>), [implementation](<https://devfeed.tech/topics/implementation.md>), [test](<https://devfeed.tech/topics/test.md>), [Code](<https://devfeed.tech/topics/code.md>)

Tags: [equals](<https://devfeed.tech/tags/equals.md>), [hash](<https://devfeed.tech/tags/hash.md>), [hashcode](<https://devfeed.tech/tags/hashcode.md>), [implement](<https://devfeed.tech/tags/implement.md>), [implementation](<https://devfeed.tech/tags/implementation.md>), [intellij](<https://devfeed.tech/tags/intellij.md>), [java](<https://devfeed.tech/tags/java.md>)

## AI overview

This article explains why Java hashCode and equals implementations must follow their documented contract. It focuses on the requirement that repeated hashCode calls on the same object during one application execution return the same integer, and demonstrates problems caused by violating it.

## Source excerpt

HashCode and equals implementations are hard. Usually, it's tricky to properly implement hashCode and equals method to fully fulfill contract from Java documentation. I'm going to focus on just one the point from the hashCode contract: whenever it is invoked on the same object more than once during an execution of a Java application, the hashCode method must consistently return the same integer. Read it already? Do it again. Let it sink and think about impact of "hashCode method must consistently return the same integer" Read more