Kotlin


1. Tooling

There are a few ways to get started.

  1. Explore the online editor at try.kotlinlang.org
  2. Get the command line tools at kotlinlang.org/commandline
  3. Use an IDE like Eclipse or IntelliJ IDEA, there is a non-paid version of IntelliJ called CE or Community Edition

2. A few characteristics

Like Java, its

Unlike Java, it


3. Functions

The main function in Kotlin is written as follows

fun main(args: Array<String>) { 
  println("Hello")
}

3.1 Default params

Function params can be assigned a default value, like this

Listing 3-1. connectDb function

fun connectDb(host: String = "localhost",
              user: String = "root",
              password: String = "password")

All the params of connectDb() have default values, so we can call this function like this

connectDb() // no arguments passed
connectDb("jupiter") // just the 1st param
connectDb("jupiter", "neptune") // 1st and 2nd params
connectDb("jupiter","neptune","saturn") // or all three

3.2 Named params

Calling functions in your code can be further improved using named parameters.

3.3 Variable args

3.4 Extension functions

3.5 Infix functions


4. Variables and Basic Types

5. Classes and Objects

6. Access Modifiers

7. Companion Objects

8. Higher Order Functions

9. Collections

10. Working with Java

11. Nullability and Java Inter-Op

12. Generics

comments powered by Disqus