# Properly implement Base.hash() for custom type

**URL:** <https://discourse.julialang.org/t/properly-implement-base-hash-for-custom-type/61951>\
**Category:** General Usage\
**Created:** [May 27, 2021, 5:56pm UTC](https://discourse.julialang.org/t/properly-implement-base-hash-for-custom-type/61951 "2021-05-27T17:56:27Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![rdeits](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rdeits/32/286_2.png) [@rdeits](https://discourse.julialang.org/u/rdeits)\
**Post date:** [May 27, 2021, 6:02pm UTC](https://discourse.julialang.org/t/properly-implement-base-hash-for-custom-type/61951/2 "2021-05-27T18:02:14Z")

</div>

I don’t think there’s any reason to supply a default for the second argument (the base `hash(x::Any)` method in `Base` will do this for you). And you can probably simplify the implementation a bit to something more like:

```julia
function hash(weapon::GameWeapon, h::UInt)
  hash(weapon.type, hash(weapon.damage, h))
end

```

---

_[View the full topic](https://discourse.julialang.org/t/properly-implement-base-hash-for-custom-type/61951)._
