In Kotlin, is there any concise way to generate a Comparable#compareTo()
function for an interface that just calls this.property1.compareTo(that.property1)
for each property of the interface in declaration order? Obviously, every property of the interface implements Comparable
.
For interface I
, it looks like I can create a top-level val like:
private val COMPARATOR = compareBy<I>(
{it.property1},
{it.property2},
{it.property3},
...
)
And return COMPARATOR.compare(this, other)
from I#compareTo(I)
, but, is there any simpler way to do this?