Keywords and Operators
- is used for type casts
- specifies an
as?
is used for safe type castsbreak
class
declares a classcontinue
do
begins a do/while loop (loop with postcondition)else
defines the branch of an which is executed when the condition is falsefalse
specifies the ‘false’ value of the Boolean typefor
begins afun
declares a functionif
begins anin
- specifies the object being iterated in a for loop
- is used as an infix operator to check that a value belongs to , a collection or another entity that defines the ‘contains’ method
- is used in for the same purpose
- marks a type parameter as contravariant
!in
- is used as an operator to check that a value does NOT belong to , a collection or another entity that defines the ‘contains’ method
- is used in for the same purpose
interface
declares an interfaceis
- checks that
- is used in when expressions for the same purpose
!is
- checks that
- is used in when expressions for the same purpose
null
is a constant representing an object reference that doesn’t point to any objectobject
declarespackage
specifies the package for the current filereturn
super
this
- refers to the current receiver
throw
throws an exceptiontrue
specifies the ‘true’ value of thetry
begins an exception handling blocktypeof
reserved for future useval
declares a read-only or local variablevar
declares a mutable or local variablewhen
begins a (executes one of the given branches)while
begins a while loop (loop with precondition)
by
catch
begins a block thatconstructor
declares a primary or secondary constructordelegate
is used as andynamic
references a dynamic type in Kotlin/JS codefield
is used as anfile
is used as an annotation use-site targetfinally
begins a block thatget
- declares the getter of a property
- is used as an
- imports a declaration from another package into the current file
init
begins anparam
is used as an annotation use-site targetproperty
is used as anreceiver
is used as an annotation use-site targetset
- declares the
- is used as an annotation use-site target
setparam
is used as anwhere
specifies constraints for a generic type parameter
actual
denotes a platform-specific implementation inabstract
marks a class or member as abstractannotation
declares ancompanion
declares a companion objectconst
marks a property as acrossinline
forbids non-local returns in a lambda passed to an inline functiondata
instructs the compiler toenum
declares an enumerationexpect
marks a declaration as , expecting an implementation in platform modules.external
marks a declaration as implemented not in Kotlin (accessible through JNI or in )final
forbids overriding a memberinfix
allows calling a function ininline
tells the compiler to inline the function and the lambdas passed to it at the call siteinner
allows referring to the outer class instance from ainternal
marks a declaration as visible in the current modulelateinit
allows initializing anoinline
turns off inlining of a lambda passed to an inline functionopen
allowsout
marks a type parameter as covariantoverride
marks a member as anprivate
marks a declaration as visible in the current class or fileprotected
marks a declaration aspublic
marks a declaration as visible anywherereified
marks a type parameter of an inline function assealed
declares a sealed class (a class with restricted subclassing)suspend
marks a function or lambda as suspending (usable as a )tailrec
marks a function as tail-recursive (allowing the compiler to replace recursion with iteration)vararg
allows
field
is used inside a property accessor to refer to the backing field of the propertyit
is used inside a lambda to
+
, ,*
,/
,%
- mathematical operators*
is also used to pass an array to a vararg parameter
=
- assignment operator
- is used to specify
+=
,-=
,*=
,/=
,%=
- augmented assignment operators++
,--
-&&
,||
,!
- logical ‘and’, ‘or’, ‘not’ operators (for bitwise operations, use corresponding infix functions)==
,!=
- (translated to calls ofequals()
for non-primitive types)===
,!==
- referential equality operators<
,>
,<=
,>=
- (translated to calls ofcompareTo()
for non-primitive types)[
,]
- indexed access operator (translated to calls ofget
andset
)!!
?.
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 )::
creates a member reference or a..
creates a range:
separates a name from a type in declarations?
marks a type as->
- separates the parameters and body of a lambda expression
- separates the parameters and return type declaration in a
- separates the condition and body of a when expression branch
@
- introduces an
- introduces or references a loop label
- introduces or references a
- references a ‘this’ expression from an outer scope
- references an
;
separates multiple statements on the same line- references a variable or expression in a string template
_
- substitutes an unused parameter in a
- substitutes an unused parameter in a destructuring declaration