Answer the question
In order to leave comments, you need to log in
How to implement custom type comparison in Go?
For example, in Python, to compare two class objects through == or >, it is enough for this class to set the methods __eq__(self, other) (equals), __gt__(self, other) (greater)
Is there something similar in Go, or do you have to do a.Greater(b) ?
Answer the question
In order to leave comments, you need to log in
There is no way in Go to override standard operators or define them for your own types.
So yeah
have to do a.Greater(b)
There is also reflect. deepequal to not implement the interface yourself.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question