# How does Kotlin implement equals and hashCode?

**URL:** <https://discuss.kotlinlang.org/t/how-does-kotlin-implement-equals-and-hashcode/940>\
**Category:** Uncategorized\
**Created:** [January 18, 2013, 3:22pm UTC](https://discuss.kotlinlang.org/t/how-does-kotlin-implement-equals-and-hashcode/940 "2013-01-18T15:22:15Z")\
**Posts on this page:** 3\
**Page:** 2

<div class="post-metadata">

**Author:** ![kyay10](https://avatars.discourse-cdn.com/v4/letter/k/c57346/32.png) [@kyay10](https://discuss.kotlinlang.org/u/kyay10)\
**Post date:** [September 4, 2021, 6:35pm UTC](https://discuss.kotlinlang.org/t/how-does-kotlin-implement-equals-and-hashcode/940/21 "2021-09-04T18:35:32Z")

</div>

Ah yes that makes a lot of sense. Does this means though that in this example:

> [@ilya.gorbunov](#):
>
> `data class BoxDouble(val value: Double)`

that the equals method is going to box `value` into a `java.lang.Double` or is it going to use the `Double.compare(d1, d2)` or equivalent method like that? In other words, does Kotlin’s auto-generated implementation of equals when you use a Double field box the double for the equality check or not? I’m guessing (and hoping) that it doesn’t

---

<div class="post-metadata">

**Author:** ![ilya.gorbunov](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/ilya.gorbunov/32/1645_2.png) [@ilya.gorbunov](https://discuss.kotlinlang.org/u/ilya.gorbunov)\
**Post date:** [September 4, 2021, 10:18pm UTC](https://discuss.kotlinlang.org/t/how-does-kotlin-implement-equals-and-hashcode/940/22 "2021-09-04T22:18:06Z")

</div>

> [@kyay10](#):
>
> In other words, does Kotlin’s auto-generated implementation of equals when you use a Double field box the double for the equality check or not?

I’ve just checked it, and turns out the new shiny JVM-IR backend does box them before comparison, whereas the old JVM backend was smart enough to call `Double.compare`. That’s a shame, should be reported to YT.

UPD: I’ve filed [https://youtrack.jetbrains.com/issue/KT-48635](https://youtrack.jetbrains.com/issue/KT-48635)

---

<div class="post-metadata">

**Author:** ![trejkaz](https://avatars.discourse-cdn.com/v4/letter/t/8797f3/32.png) [@trejkaz](https://discuss.kotlinlang.org/u/trejkaz)\
**Post date:** [February 2, 2022, 10:20pm UTC](https://discuss.kotlinlang.org/t/how-does-kotlin-implement-equals-and-hashcode/940/23 "2022-02-02T22:20:26Z")

</div>

Got bitten by this again recently.

When you have arrays in a data class you get a warning that you should probably customise `equals` and `hashCode`… I’m starting to think I should also get the same warning for `Double`.

[Previous page](https://discuss.kotlinlang.org/t/how-does-kotlin-implement-equals-and-hashcode/940.md?page=1)
