compare Values
Начиная с Kotlin: 1.0
fun <T : Comparable<*>> compareValues(a: T?, b: T?): Int
Сравнивает два nullable-значения Comparable. Null считается меньше любого значения.
Примеры
import kotlin.test.*
fun main() {
//sampleStart
println("compareValues(null, 1) < 0 is ${compareValues(null, 1) < 0}") // true
println("compareValues(1, 2) < 0 is ${compareValues(1, 2) < 0}") // true
println("compareValues(2, 1) > 0 is ${compareValues(2, 1) > 0}") // true
println("compareValues(1, 1) == 0 is ${compareValues(1, 1) == 0}") // true
//sampleEnd
}
© 2010–2026 JetBrains s.r.o. and Kotlin Programming Language contributors
Licensed under the Apache License, Version 2.0.
https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.comparisons/compare-values.html