Comparable

interface Comparable<in T> (source)

Classes which inherit from this interface have a defined total ordering between their instances.

Functions

compareTo

abstract operator fun compareTo(other: T): Int

Compares this object with the specified object for order. Returns zero if this object is equal to the specified other object, a negative number if it's less than other, or a positive number if it's greater than other.

Inherited Functions

equals

open operator fun equals(other: Any?): Boolean

Indicates whether some other object is "equal to" this one. Implementations must fulfil the following requirements:

hashCode

open fun hashCode(): Int

Returns a hash code value for the object. The general contract of hashCode is:

toString

open fun toString(): String

Returns a string representation of the object.

Extension Functions

coerceAtLeast

fun <T : Comparable<T>> T.coerceAtLeast(minimumValue: T): T

Ensures that this value is not less than the specified minimumValue.

coerceAtMost

fun <T : Comparable<T>> T.coerceAtMost(maximumValue: T): T

Ensures that this value is not greater than the specified maximumValue.

coerceIn

fun <T : Comparable<T>> T.coerceIn(
    minimumValue: T?,
    maximumValue: T?
): T

Ensures that this value lies in the specified range minimumValue..maximumValue.

fun <T : Comparable<T>> T.coerceIn(
    range: ClosedFloatingPointRange<T>
): T
fun <T : Comparable<T>> T.coerceIn(range: ClosedRange<T>): T

Ensures that this value lies in the specified range.

rangeTo

operator fun <T : Comparable<T>> T.rangeTo(
    that: T
): ClosedRange<T>

Creates a range from this Comparable value to the specified that value.

Inheritors

Boolean

class Boolean : Comparable<Boolean>

Represents a value which is either true or false. On the JVM, non-nullable values of this type are represented as values of the primitive type boolean.

Byte

class Byte : Number, Comparable<Byte>

Represents a 8-bit signed integer. On the JVM, non-nullable values of this type are represented as values of the primitive type byte.

Char

class Char : Comparable<Char>

Represents a 16-bit Unicode character. On the JVM, non-nullable values of this type are represented as values of the primitive type char.

Double

class Double : Number, Comparable<Double>

Represents a double-precision 64-bit IEEE 754 floating point number. On the JVM, non-nullable values of this type are represented as values of the primitive type double.

Enum

abstract class Enum<E : Enum<E>> : Comparable<E>

The common base class of all enum classes. See the Kotlin language documentation for more information on enum classes.

Float

class Float : Number, Comparable<Float>

Represents a single-precision 32-bit IEEE 754 floating point number. On the JVM, non-nullable values of this type are represented as values of the primitive type float.

Int

class Int : Number, Comparable<Int>

Represents a 32-bit signed integer. On the JVM, non-nullable values of this type are represented as values of the primitive type int.

KotlinVersion

class KotlinVersion : Comparable<KotlinVersion>

Represents a version of the Kotlin standard library.

Long

class Long : Number, Comparable<Long>

Represents a 64-bit signed integer. On the JVM, non-nullable values of this type are represented as values of the primitive type long.

Short

class Short : Number, Comparable<Short>

Represents a 16-bit signed integer. On the JVM, non-nullable values of this type are represented as values of the primitive type short.

String

class String : Comparable<String>, CharSequence

The String class represents character strings. All string literals in Kotlin programs, such as "abc", are implemented as instances of this class.