Variables
1 | // readonly variable |
Types in Kotlin are by default non-nullable
1 | // Create a nullable string |
Type declaration can be omitted in Kotlin
1 | var name = "Nate" |
Flow control
when
statement behaves similar to switch
1 | when(name) { |
Basic Functions
1 | fun getGreeting(): String { |
Function parameters and spread operator
1 | fun sayHello(greeting: String, vararg itemsToGreet: String) { |
Named arguments and default arguments.
Once an argument is named, other arguments should also be named
1 | fun greetPerson(greeting: String = "Hello", name: String = "Kotlin") = println("$greeting $name") |
Iteration
Array, List, and Map
1 | // array type can be inferred from the input |
Classes
1 | class Person (_firstName: String, _lastName: String) { |