thenDescending所在位置是kotlin.comparisons.thenDescending,其相關用法介紹如下。

用法:

infix fun <T> Comparator<T>.thenDescending(
    comparator: Comparator<in T>
): Comparator<T>

將此比較器與給定的comparator 結合起來,以便僅當前者認為值相等時才應用後者。

例子:

import kotlin.test.*

fun main(args: Array<String>) {
//sampleStart
val list = listOf("A", "aa", "b", "bb", "a")

val lengthThenCaseInsensitive = compareBy<String> { it.length }
    .thenDescending(String.CASE_INSENSITIVE_ORDER)

val sorted = list.sortedWith(lengthThenCaseInsensitive)

println(sorted) // [b, A, a, bb, aa]
//sampleEnd
}

輸出:

[b, A, a, bb, aa]