compareValues

fun <T : Comparable<*>> compareValues(a: T?, b: T?): Int(source)

Compares two nullable Comparable values. Null is considered less than any value.

Since Kotlin

1.1

Samples

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
}
fun <T : Comparable<*>> compareValues(a: T?, b: T?): Int(source)

Compares two nullable Comparable values. Null is considered less than any value.

Since Kotlin

1.0

Samples

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
}