hashCode returns the same constant for every object, which puts all of them in one bucket of a hash table

tx0/kotlin:constant-hash-coderecommendedwarningperformance/algorithmicdepth fastperformance

What it finds

A constant hashCode keeps the contract but turns every HashMap and HashSet holding these objects into a list, with lookups in linear time.

From the rule's source, constant_hash_code.rs.

Example from the rule's tests
class Key(val id: Int) {    override fun hashCode(): Int = 42tx0 reports: every object has the same hash code} class Other(val id: Int) {    override fun hashCode(): Int = id}
Highlighted lines are the ones tx0 reports, with its message under each; the other lines are left alone.

Turn it on, off or suppress it

The rule runs from the recommended tier up. To turn it on in a lower tier, give it a level in tx0.toml:

tx0.toml
[rules]
"tx0/kotlin:constant-hash-code" = "warning"

To keep one finding, suppress it with a reason. tx0 suppress ID --reason "..." writes the comment on the line before the code:

// tx0: ignore[tx0/kotlin:constant-hash-code] reason="..."

tx0 explain tx0/kotlin:constant-hash-code shows the same in the terminal. Found a false positive? Report it.