I believe it could confuse a reader who assumes th...
# stdlib
i
I believe it could confuse a reader who assumes that
compareTo
and related operators usually come from implementation of
Comparable
— he could make wrong conclusions about the contract. If I ultimately need to have such operator overloads I would scope them as narrow as possible, for example with member-extensions:
Copy code
object MyPartialOrderComparator: Comparator<Class<*>> {
    override fun compare(p0: Class<*>?, p1: Class<*>?): Int = TODO()

    operator fun Class<*>.compareTo(other: Class<*>): Int = compare(this, other)
}


fun partialOrderUsage(c1: Class<*>, c2: Class<*>): Boolean {
    with (MyPartialOrderComparator) {
        return (c1 < c2) || (c1 > c2)
    }
}
Here a reader would have more chances to notice that it's not usual
greater than
and
less than
operators and that the
MyPartialOrderComparator
could be somehow involved in semantics of comparisons.