I am trying to convert this code from java to Kotlin:
Comparator.<Pair<String, Integer>, Integer>comparing(Pair::getSecond)
.reversed()
.thenComparing(Pair::getFirst);
Intellij notes that Pair is deprecated. I am trying to find the idiomatic kotlin way to write this out. However, intellij produces this:
companion object {
private val COUNT_COUNTRY_COMPARATOR = Comparator.comparing { obj: Pair<String?, Int?> -> obj.second }
.reversed()
.thenComparing { obj: Pair<String?, Int?> -> obj.first }
}
This will not compile with the error:
Type mismatch.
Required:
TypeVariable(U)!
Found:
Int?
Between Comparator, deprecated Pair, and the strange conversion, I am wondering if there is a better way to write this in Kotlin.