Keywords and operators
The following tokens are always interpreted as keywords and cannot be used as identifiers:
as?is used for safe type casts.
classdeclares a class.
dobegins a do/while loop (a loop with a postcondition).
elsedefines the branch of an if expression that is executed when the condition is false.
falsespecifies the 'false' value of the Boolean type.
forbegins a for loop.
fundeclares a function.
ifbegins an if expression.
interfacedeclares an interface.
nullis a constant representing an object reference that doesn't point to any object.
objectdeclares a class and its instance at the same time.
packagespecifies the package for the current file.
throwthrows an exception.
truespecifies the 'true' value of the Boolean type.
typealiasdeclares a type alias.
typeofis reserved for future use.
whenbegins a when expression (executes one of the given branches).
whilebegins a while loop (a loop with a precondition).
The following tokens act as keywords in the context in which they are applicable, and they can be used as identifiers in other contexts:
catchbegins a block that handles a specific exception type.
constructordeclares a primary or secondary constructor.
delegateis used as an annotation use-site target.
dynamicreferences a dynamic type in Kotlin/JS code.
fieldis used as an annotation use-site target.
fileis used as an annotation use-site target.
finallybegins a block that is always executed when a try block exits.
initbegins an initializer block.
paramis used as an annotation use-site target.
propertyis used as an annotation use-site target.
receiveris used as an annotation use-site target.
setparamis used as an annotation use-site target.
classkeyword declares an inline class.
wherespecifies the constraints for a generic type parameter.
The following tokens act as keywords in modifier lists of declarations, and they can be used as identifiers in other contexts:
abstractmarks a class or member as abstract.
actualdenotes a platform-specific implementation in multiplatform projects.
annotationdeclares an annotation class.
companiondeclares a companion object.
constmarks a property as a compile-time constant.
crossinlineforbids non-local returns in a lambda passed to an inline function.
datainstructs the compiler to generate canonical members for a class.
enumdeclares an enumeration.
expectmarks a declaration as platform-specific, expecting an implementation in platform modules.
finalforbids overriding a member.
infixallows calling a function using infix notation.
inlinetells the compiler to inline a function and the lambdas passed to it at the call site.
innerallows referring to an outer class instance from a nested class.
internalmarks a declaration as visible in the current module.
lateinitallows initializing a non-nullable property outside of a constructor.
noinlineturns off inlining of a lambda passed to an inline function.
openallows subclassing a class or overriding a member.
operatormarks a function as overloading an operator or implementing a convention.
outmarks a type parameter as covariant.
overridemarks a member as an override of a superclass member.
privatemarks a declaration as visible in the current class or file.
protectedmarks a declaration as visible in the current class and its subclasses.
publicmarks a declaration as visible anywhere.
reifiedmarks a type parameter of an inline function as accessible at runtime.
sealeddeclares a sealed class (a class with restricted subclassing).
suspendmarks a function or lambda as suspending (usable as a coroutine).
tailrecmarks a function as tail-recursive (allowing the compiler to replace recursion with iteration).
varargallows passing a variable number of arguments for a parameter.
The following identifiers are defined by the compiler in specific contexts, and they can be used as regular identifiers in other contexts:
Operators and special symbols
Kotlin supports the following operators and special symbols:
%- mathematical operators
*is also used to pass an array to a vararg parameter.
is used to specify default values for parameters.
%=- augmented assignment operators.
--- increment and decrement operators.
!- logical 'and', 'or', 'not' operators (for bitwise operations, use the corresponding infix functions instead).
!=- 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
?.performs a safe call (calls a method or accesses a property if the receiver is non-nullable).
?:takes the right-hand value if the left-hand value is null (the elvis operator).
:separates a name from a type in a declaration.
?marks a type as nullable.
;separates multiple statements on the same line.
$references a variable or expression in a string template.
For operator precedence, see this reference in Kotlin grammar.