cast object without first checking it has right type- kotlin combines check and cast into single operation
Back
variables
Front
no type needed, if no initializer then must have explicit type
Back
default modifier
Front
public and can be omitted
Back
block body
Front
a function written with it's body in curly braces
Back
function return
Front
comes after parameter, separated by semicolon
Back
function parameter
Front
type is written after it's name
Back
triple quoted string
Front
don't need to eacaps any symbols.
Back
var
Front
for variable, mutable
Back
val
Front
for value, immutable reference, object it points to can be mutable
Back
value objects
Front
classes containing only data and no code
Back
how to print
Front
write println
Back
Why use Kotlin
Front
a. statically typed, b. support nullable types, c. function types, d. open source
Back
expression body
Front
function returning an expression directly
Back
Functional Programming
Front
a. first-class functions as values, b. immutability- state can't change after creation, c. no side effects- pure functions return same results given same input and don't interact with outside world
Back
assignments
Front
statements- top-level element in enclosing block and doesn't have it's own value
Back
public
Front
default visibility so can be omitted
Back
destructuring declaration
Front
initialize two variables with the contents of a Pair directly
val (number, name) = 1 to "one"
Back
type inference
Front
compiler analyzes data type of expression
Back
Nullable
Front
marking type as nullable done by adding question mark
Back
extension function
Front
a function that can be called as a member of a class but is defined outside of it.
Back
if
Front
an expression with result value- similar to ternary
Back
string templates
Front
use $ in front of variable name, {$} when more complex like args[0]
Back
property
Front
declare with val or var, accessors created automatically, call properties directly without referencing getter or setter. person.isMarried=false
Back
fun
Front
declaration for function, can be top level of file, outside class
Back
infix call
Front
method name is placed immediately between the target object name and the parameter, with no extra separators
infix fun Any.to(other: Any) = Pair(this, other)
Back
property
Front
combination of field and accessors, val has getter and var has getter and setter