# Different structs with the same properties

**URL:** <https://discourse.julialang.org/t/different-structs-with-the-same-properties/104417>\
**Category:** General Usage\
**Tags:** struct\
**Created:** [September 30, 2023, 1:41am UTC](https://discourse.julialang.org/t/different-structs-with-the-same-properties/104417 "2023-09-30T01:41:24Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![gdalle](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gdalle/32/27854_2.png) [@gdalle](https://discourse.julialang.org/u/gdalle)\
**Post date:** [September 30, 2023, 7:26am UTC](https://discourse.julialang.org/t/different-structs-with-the-same-properties/104417/2 "2023-09-30T07:26:33Z")

</div>

I think it is because the default implementation of `==` for a new `struct` falls back on `===`, which tests if the two objects share the same memory address (i.e. if they are one and the same). If your struct includes mutable fields, you need to redefine `Base.:(==)` for your own struct in a way that compares field values instead.

> <https://github.com/JuliaLang/julia/issues/4648>
>
> This doesn't make much sense:
> 
> \`\`\` julia
> julia\> immutable Foo{T}
> bar::T…
> end
> 
> julia\> Foo("baz") == Foo("baz")
> false
> 
> julia\> Foo("baz").bar == Foo("baz").bar
> true
> 
> julia\> Foo(1) == Foo(1)
> true
> \`\`\`
> 
> If the fields are \`==\` to each other then the objects should be \`==\` to each other.

> [@Surprising struct equality test](https://discourse.julialang.org/t/surprising-struct-equality-test/4890/):
>
> By my understanding of structs, they should be compared by value by default. So what is going here?? struct T name::String end T("hello") == T("hello") returns false!

---

_[View the full topic](https://discourse.julialang.org/t/different-structs-with-the-same-properties/104417)._
