# Surprising struct equality test

**URL:** <https://discourse.julialang.org/t/surprising-struct-equality-test/4890>\
**Category:** General Usage\
**Tags:** question\
**Created:** [July 17, 2017, 12:24am UTC](https://discourse.julialang.org/t/surprising-struct-equality-test/4890 "2017-07-17T00:24:30Z")\
**Posts on this page:** 1\
**Showing post:** 8

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [July 17, 2017, 9:08am UTC](https://discourse.julialang.org/t/surprising-struct-equality-test/4890/8 "2017-07-17T09:08:42Z")

</div>

A function could rely on existing behavior of `==`. If you change that, you could break code.

> [@e3c6](#):
>
> `Base.:(==)(x::T, y::T) = x.name == y.name`

Your code is nonsensical, and won’t even compile.

As for hashing, see [the manual](https://docs.julialang.org/en/latest/stdlib/base/#Base.hash). Or as an example,

> **[GitHub - JuliaServices/AutoHashEquals.jl: A Julia macro to add == and hash()...](https://github.com/JuliaServices/AutoHashEquals.jl)**
>
> A Julia macro to add == and hash() to composite types. - GitHub - JuliaServices/AutoHashEquals.jl: A Julia macro to add == and hash() to composite types.

---

_[View the full topic](https://discourse.julialang.org/t/surprising-struct-equality-test/4890)._
