I've defined a wrapper class:
class Wrapper[T](private val value: T)
and I want to make sure that w(v1) == v2 and v2 == w(v1) iff v1 == v2. The first part is easy because you can override equals method of Wrapper class. But the problem is the other way around, making 5 == Wrapper(5) return true for example, achieving symmetry of equality. Is it possible in scala that you can override equals method of basic types like Int or String? In C++, you can override both operator==(A, int) and operator==(int, A) but it doesn't seem so with java or scala.
equals
has signatureequals(x: Any): Boolean
andT
is erased. – Victor Moroz==
? It's easy to define a standalone method in both directions, or define another method implicitly. You can't really override==
inInt
as it's already there. – Victor Moroz