kotlin

Package kotlin

Core functions and types, available on all supported platforms-

Types

Annotation

interface Annotation

Base interface implicitly implemented by all annotation interfaces. See Kotlin language documentation for more information on annotations.

Any

open class Any

The root of the Kotlin class hierarchy. Every Kotlin class has Any as a superclass.

Array

class Array<T>

Represents an array (specifically, a Java array when targeting the JVM platform). Array instances can be created using the arrayOf, arrayOfNulls and emptyArray standard library functions. See Kotlin language documentation for more information on arrays.

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.

BooleanArray

class BooleanArray

An array of booleans. When targeting the JVM, instances of this class are represented as 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.

ByteArray

class ByteArray

An array of bytes. When targeting the JVM, instances of this class are represented as 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.

CharArray

class CharArray

An array of chars. When targeting the JVM, instances of this class are represented as char[].

CharSequence

interface CharSequence

Represents a readable sequence of Char values.

Comparable

interface Comparable<in T>

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

ConcurrentModificationException

open class ConcurrentModificationException : RuntimeException

DeprecationLevel

enum class DeprecationLevel

Contains levels for deprecation levels.

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.

DoubleArray

class DoubleArray

An array of doubles. When targeting the JVM, instances of this class are represented as 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.

FloatArray

class FloatArray

An array of floats. When targeting the JVM, instances of this class are represented as float[].

Function

interface Function<out R>

Represents a value of a functional type, such as a lambda, an anonymous function or a function reference.

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.

IntArray

class IntArray

An array of ints. When targeting the JVM, instances of this class are represented as int[].

KotlinVersion

class KotlinVersion : Comparable<KotlinVersion>

Represents a version of the Kotlin standard library.

Lazy

interface Lazy<out T>

Represents a value with lazy initialization.

LazyThreadSafetyMode

enum class LazyThreadSafetyMode

Specifies how a Lazy instance synchronizes access among multiple threads.

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.

LongArray

class LongArray

An array of longs. When targeting the JVM, instances of this class are represented as long[].

NoWhenBranchMatchedException

open class NoWhenBranchMatchedException : RuntimeException

Nothing

class Nothing

Nothing has no instances. You can use Nothing to represent "a value that never exists": for example, if a function has the return type of Nothing, it means that it never returns (always throws an exception).

Number

abstract class Number

Superclass for all platform classes representing numeric values.

Pair

data class Pair<out A, out B> : Serializable

Represents a generic pair of two values.

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.

ShortArray

class ShortArray

An array of shorts. When targeting the JVM, instances of this class are represented as 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.

Throwable

open class Throwable

The base class for all errors and exceptions. Only instances of this class can be thrown or caught.

Triple

data class Triple<out A, out B, out C> : Serializable

Represents a triad of values

Unit

object Unit

The type with only one value: the Unit object. This type corresponds to the void type in Java.

Annotations

Deprecated

annotation class Deprecated

Marks the annotated class, function, property, variable or parameter as deprecated.

DslMarker

annotation class DslMarker

When applied to annotation class X specifies that X defines a DSL language

ExtensionFunctionType

annotation class ExtensionFunctionType

Signifies that the annotated functional type represents an extension function.

ParameterName

annotation class ParameterName

Annotates type arguments of functional type and holds corresponding parameter name specified by the user in type declaration (if any).

PublishedApi

annotation class PublishedApi

Specifies that this part of internal API is effectively public exposed by using in public inline function

ReplaceWith

annotation class ReplaceWith

Specifies a code fragment that can be used to replace a deprecated function, property or class. Tools such as IDEs can automatically apply the replacements specified through this annotation.

SinceKotlin

annotation class SinceKotlin

Specifies the first version of Kotlin where a declaration has appeared. Using the declaration and specifying an older API version (via the -api-version command line option) will result in an error.

Suppress

annotation class Suppress

Suppresses the given compilation warnings in the annotated element.

Synchronized

annotation class Synchronized

UnsafeVariance

annotation class UnsafeVariance

Suppresses errors about variance conflict

Volatile

annotation class Volatile

Exceptions

NotImplementedError

class NotImplementedError : Error

An exception is thrown to indicate that a method body remains to be implemented.

Type Aliases

AssertionError

typealias AssertionError = AssertionError

ClassCastException

typealias ClassCastException = ClassCastException

Comparator

typealias Comparator<T> = Comparator<T>

Error

typealias Error = Error

Exception

typealias Exception = Exception

IllegalArgumentException

typealias IllegalArgumentException = IllegalArgumentException

IllegalStateException

typealias IllegalStateException = IllegalStateException

IndexOutOfBoundsException

typealias IndexOutOfBoundsException = IndexOutOfBoundsException

NoSuchElementException

typealias NoSuchElementException = NoSuchElementException

NullPointerException

typealias NullPointerException = NullPointerException

NumberFormatException

typealias NumberFormatException = NumberFormatException

RuntimeException

typealias RuntimeException = RuntimeException

UnsupportedOperationException

typealias UnsupportedOperationException = UnsupportedOperationException

Extensions for External Classes

java.math.BigDecimal

java.math.BigInteger

Properties

stackTrace

val Throwable.stackTrace: Array<StackTraceElement>

Returns an array of stack trace elements representing the stack trace pertaining to this throwable.

Functions

Comparator

fun <T> Comparator(
    comparison: (a: T, b: T) -> Int
): Comparator<T>

TODO

fun TODO(): Nothing
fun TODO(reason: String): Nothing

Always throws NotImplementedError stating that operation is not implemented.

addSuppressed

fun Throwable.addSuppressed(exception: Throwable)

When supported by the platform adds the specified exception to the list of exceptions that were suppressed in order to deliver this exception.

also

fun <T> T.also(block: (T) -> Unit): T

Calls the specified function block with this value as its argument and returns this value.

apply

fun <T> T.apply(block: T.() -> Unit): T

Calls the specified function block with this value as its receiver and returns this value.

arrayOf

fun <T> arrayOf(vararg elements: T): Array<T>

Returns an array containing the specified elements.

arrayOfNulls

fun <T> arrayOfNulls(size: Int): Array<T?>

Returns an array of objects of the given type with the given size, initialized with null values.

assert

fun assert(value: Boolean)

Throws an AssertionError if the value is false and runtime assertions have been enabled on the JVM using the -ea JVM option.

fun assert(value: Boolean, lazyMessage: () -> Any)

Throws an AssertionError calculated by lazyMessage if the value is false and runtime assertions have been enabled on the JVM using the -ea JVM option.

booleanArrayOf

fun booleanArrayOf(vararg elements: Boolean): BooleanArray

Returns an array containing the specified boolean values.

byteArrayOf

fun byteArrayOf(vararg elements: Byte): ByteArray

Returns an array containing the specified Byte numbers.

charArrayOf

fun charArrayOf(vararg elements: Char): CharArray

Returns an array containing the specified characters.

check

fun check(value: Boolean)

Throws an IllegalStateException if the value is false.

fun check(value: Boolean, lazyMessage: () -> Any)

Throws an IllegalStateException with the result of calling lazyMessage if the value is false.

checkNotNull

fun <T : Any> checkNotNull(value: T?): T

Throws an IllegalStateException if the value is null. Otherwise returns the not null value.

fun <T : Any> checkNotNull(
    value: T?, 
    lazyMessage: () -> Any
): T

Throws an IllegalStateException with the result of calling lazyMessage if the value is null. Otherwise returns the not null value.

doubleArrayOf

fun doubleArrayOf(vararg elements: Double): DoubleArray

Returns an array containing the specified Double numbers.

emptyArray

fun <T> emptyArray(): Array<T>

Returns an empty array of the specified type T.

enumValueOf

fun <T : Enum<T>> enumValueOf(name: String): T

Returns an enum entry with specified name.

enumValues

fun <T : Enum<T>> enumValues(): Array<T>

Returns an array containing enum T entries.

error

fun error(message: Any): Nothing

Throws an IllegalStateException with the given message.

floatArrayOf

fun floatArrayOf(vararg elements: Float): FloatArray

Returns an array containing the specified Float numbers.

getValue

operator fun <T> Lazy<T>.getValue(
    thisRef: Any?, 
    property: KProperty<*>
): T

An extension to delegate a read-only property of type T to an instance of Lazy.

intArrayOf

fun intArrayOf(vararg elements: Int): IntArray

Returns an array containing the specified Int numbers.

isFinite

fun Double.isFinite(): Boolean
fun Float.isFinite(): Boolean

Returns true if the argument is a finite floating-point value; returns false otherwise (for NaN and infinity arguments).

isInfinite

fun Double.isInfinite(): Boolean
fun Float.isInfinite(): Boolean

Returns true if this value is infinitely large in magnitude.

isNaN

fun Double.isNaN(): Boolean
fun Float.isNaN(): Boolean

Returns true if the specified number is a Not-a-Number (NaN) value, false otherwise.

lazy

fun <T> lazy(initializer: () -> T): Lazy<T>
fun <T> lazy(lock: Any?, initializer: () -> T): Lazy<T>

Creates a new instance of the Lazy that uses the specified initialization function initializer and the default thread-safety mode LazyThreadSafetyMode.SYNCHRONIZED.

fun <T> lazy(
    mode: LazyThreadSafetyMode, 
    initializer: () -> T
): Lazy<T>

Creates a new instance of the Lazy that uses the specified initialization function initializer and thread-safety mode.

lazyOf

fun <T> lazyOf(value: T): Lazy<T>

Creates a new instance of the Lazy that is already initialized with the specified value.

let

fun <T, R> T.let(block: (T) -> R): R

Calls the specified function block with this value as its argument and returns its result.

longArrayOf

fun longArrayOf(vararg elements: Long): LongArray

Returns an array containing the specified Long numbers.

plus

operator fun String?.plus(other: Any?): String

Concatenates this string with the string representation of the given other object. If either the receiver or the other object are null, they are represented as the string "null".

printStackTrace

fun Throwable.printStackTrace()

Prints the stack trace of this throwable to the standard output.

fun Throwable.printStackTrace(writer: PrintWriter)

Prints the stack trace of this throwable to the specified writer.

fun Throwable.printStackTrace(stream: PrintStream)

Prints the stack trace of this throwable to the specified stream.

repeat

fun repeat(times: Int, action: (Int) -> Unit)

Executes the given function action specified number of times.

require

fun require(value: Boolean)

Throws an IllegalArgumentException if the value is false.

fun require(value: Boolean, lazyMessage: () -> Any)

Throws an IllegalArgumentException with the result of calling lazyMessage if the value is false.

requireNotNull

fun <T : Any> requireNotNull(value: T?): T

Throws an IllegalArgumentException if the value is null. Otherwise returns the not null value.

fun <T : Any> requireNotNull(
    value: T?, 
    lazyMessage: () -> Any
): T

Throws an IllegalArgumentException with the result of calling lazyMessage if the value is null. Otherwise returns the not null value.

run

fun <R> run(block: () -> R): R

Calls the specified function block and returns its result.

fun <T, R> T.run(block: T.() -> R): R

Calls the specified function block with this value as its receiver and returns its result.

shortArrayOf

fun shortArrayOf(vararg elements: Short): ShortArray

Returns an array containing the specified Short numbers.

synchronized

fun <R> synchronized(lock: Any, block: () -> R): R

Executes the given function block while holding the monitor of the given object lock.

takeIf

fun <T> T.takeIf(predicate: (T) -> Boolean): T?

Returns this value if it satisfies the given predicate or null, if it doesn't.

takeUnless

fun <T> T.takeUnless(predicate: (T) -> Boolean): T?

Returns this value if it does not satisfy the given predicate or null, if it does.

to

infix fun <A, B> A.to(that: B): Pair<A, B>

Creates a tuple of type Pair from this and that.

toList

fun <T> Pair<T, T>.toList(): List<T>

Converts this pair into a list.

fun <T> Triple<T, T, T>.toList(): List<T>

Converts this triple into a list.

toString

fun Any?.toString(): String

Returns a string representation of the object. Can be called with a null receiver, in which case it returns the string "null".

use

fun <T : AutoCloseable?, R> T.use(block: (T) -> R): R

Executes the given block function on this resource and then closes it down correctly whether an exception is thrown or not.

with

fun <T, R> with(receiver: T, block: T.() -> R): R

Calls the specified function block with the given receiver as its receiver and returns its result.

© 2010–2017 JetBrains s.r.o.
Licensed under the Apache License, Version 2.0.
https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/

在线笔记
App下载
App下载

扫描二维码

下载编程狮App

公众号
微信公众号

编程狮公众号

意见反馈
返回顶部