The following tokens are always interpreted as keywords and cannot be used as identifiers:
as
as?
is used for safe type casts
break
terminates the execution of a loop
class
declares a class
continue
proceeds to the next step of the nearest enclosing loop
do
begins a do/while loop (loop with postcondition)else
defines the branch of an if expression which is executed when the condition is falsefalse
specifies the 'false' value of the Boolean type
for
begins a for loop
fun
declares a function
if
begins an if expression
in
!in
interface
declares an interface
is
!is
null
is a constant representing an object reference that doesn't point to any objectobject
declares a class and its instance at the same time
package
specifies the package for the current file
return
returns from the nearest enclosing function or anonymous function
super
this
throw
throws an exception
true
specifies the 'true' value of the Boolean type
try
begins an exception handling block
typealias
declares a type alias
val
declares a read-only property or local variable
var
declares a mutable property or local variable
when
begins a when expression (executes one of the given branches)while
begins a while loop (loop with precondition)The following tokens act as keywords in the context when they are applicable and can be used as identifiers in other contexts:
by
catch
begins a block that handles a specific exception type
constructor
declares a primary or secondary constructor
delegate
is used as an annotation use-site target
dynamic
references a dynamic type in Kotlin/JS codefield
is used as an annotation use-site target
file
is used as an annotation use-site target
finally
begins a block that is always executed when a try block exits
get
import
imports a declaration from another package into the current file
init
begins an initializer block
param
is used as an annotation use-site target
property
is used as an annotation use-site target
receiver
is used as an annotation use-site target
set
setparam
is used as an annotation use-site target
where
specifies constraints for a generic type parameter
The following tokens act as keywords in modifier lists of declarations and can be used as identifiers in other contexts:
actual
denotes a platform-specific implementation in multiplatform projects
abstract
marks a class or member as abstract
annotation
declares an annotation class
companion
declares a companion object
const
marks a property as a compile-time constant
crossinline
forbids non-local returns in a lambda passed to an inline function
data
instructs the compiler to generate canonical members for a class
enum
declares an enumeration
expect
marks a declaration as platform-specific, expecting an implementation in platform modules.external
marks a declaration as implemented not in Kotlin (accessible through JNI or in JavaScript)final
forbids overriding a member
infix
allows calling a function in infix notation
inline
tells the compiler to inline the function and the lambdas passed to it at the call site
inner
allows referring to the outer class instance from a nested class
internal
marks a declaration as visible in the current module
lateinit
allows initializing a non-null property outside of a constructor
noinline
turns off inlining of a lambda passed to an inline function
open
allows subclassing a class or overriding a member
operator
marks a function as overloading an operator or implementing a convention
out
marks a type parameter as covariant
override
marks a member as an override of a superclass member
private
marks a declaration as visible in the current class or file
protected
marks a declaration as visible in the current class and its subclasses
public
marks a declaration as visible anywhere
reified
marks a type parameter of an inline function as accessible at runtime
sealed
declares a sealed class (a class with restricted subclassing)suspend
marks a function or lambda as suspending (usable as a coroutine)tailrec
marks a function as tail-recursive (allowing the compiler to replace recursion with iteration)vararg
allows passing a variable number of arguments for a parameter
The following identifiers are defined by the compiler in specific contexts and can be used as regular identifiers in other contexts:
field
is used inside a property accessor to refer to the backing field of the property
it
is used inside a lambda to refer to its parameter implicitly
Kotlin supports the following operators and special symbols:
+
, -
, *
, /
, %
- mathematical operators *
is also used to pass an array to a vararg parameter
=
+=
, -=
, *=
, /=
, %=
- augmented assignment operators
++
, --
- increment and decrement operators
&&
, ||
, !
- logical 'and', 'or', 'not' operators (for bitwise operations, use corresponding infix functions)==
, !=
- equality operators (translated to calls of equals()
for non-primitive types)===
, !==
- referential equality operators
<
, >
, <=
, >=
- comparison operators (translated to calls of compareTo()
for non-primitive types)[
, ]
- indexed access operator (translated to calls of get
and set
)!!
asserts that an expression is non-null
?.
performs a safe call (calls a method or accesses a property if the receiver is non-null)?:
takes the right-hand value if the left-hand value is null (the elvis operator)::
creates a member reference or a class reference
..
creates a range
:
separates a name from a type in declarations?
marks a type as nullable
->
@
;
separates multiple statements on the same line$
references a variable or expression in a string template
_
© 2010–2019 JetBrains s.r.o.
Licensed under the Apache License, Version 2.0.
https://kotlinlang.org/docs/reference/keyword-reference.html