Kotlin for Android
What Kotlin is?
from http://kotl.in/
Basic syntax differences from Java
Java
Kotlin


Optional
semicolons!
Basic syntax differences from Java


'fun' keyword
Basic syntax differences from Java


no more primitive types!
everything is an object
Basic syntax differences from Java


var & val
keywords
Basic syntax differences from Java


Java
getters &
setters
as
properties
Basic syntax differences from Java


String templates
Basic syntax differences from Java




no 'new' keyword
Basic syntax differences from Java


Singleton

Basic syntax differences from Java

JavaBeans...
too much boilerplate code
Basic syntax differences from Java

so Kotlin comes with...
data classes!
equals() / hashCode(), toString(), copy()
defined automatically!
Basic syntax differences from Java
Another key features
- null safety
- not checked exceptions
- getters & setters
- delegations
- lateinit
- named & optional arguments
- lambdas
- extension functions
- type aliases
Null Safety


nullable references:
safe calls:
Null Safety


too many safe calls?
smart cast (after explicit check) for that:
Null Safety


elvis operator:
!! operator:

safe casts (avoiding ClassCastException):
Getters and Setters

lazy delegation & lateinit

Named & optional arguments


Lambdas

Extension Functions

Type Aliases

Java Interop

Java & Kotlin code in one place:
Java Interop
Calling Java code in Kotlin:

Java Interop
SAM Conversions:


Java Interop
Calling Kotlin code in Java:


Fast configuration



Kotlin Android Extensions

Kotlin Android Extensions

Kotlin Android Extensions

Anko

Why Kotlin
for Android?
We have scala, groovy, ceylon...
Kotlin in numbers*...



*from "Using Project Kotlin for Android" by Jake Wharton
More
- Kotlin is developed by JetBrains
- It compiles at least as fast as Java
Any drawbacks?
We are still waiting for Kotlin 1.0
Any drawbacks?
We are still waiting for Kotlin 1.0
"Only very brave souls are using Kotlin for production now" - Andrey Breslav (JetBrains)
Resources
Official Kotlin website:
Frameworks for Android:
https://github.com/JetBrains/anko
https://github.com/pawegio/KAndroid
Misc:
Thank you!
