Is it possible to define equality for named types/structs?

后端 未结 3 813
醉酒成梦
醉酒成梦 2021-02-11 23:32

After reading a related question about using slices in maps, I became curious about equality in Go.

I know it\'s possible to override the equals method of a

3条回答
  •  孤独总比滥情好
    2021-02-11 23:52

    No, this is not user-definable. Go has strict rules what counts as equal, and even what is comparable which itself is based on assignability. Take a look at the Comparison operators section of the spec.

提交回复
热议问题