Kotlin Android
Kotlin Android
Mike Gouline
Android Developer
Agenda
Case study
Migration guide
Community adoption
Current issues
Future releases
Summary
Background
Background
val str2: String = "I am not null" String str2 = "I am not null";
str2.trim() // no need for "?." str2.trim(); // runs
Lambdas
KOTLIN
JAVA
JAVA
public static class Island {
private String mName;
// Kotlin code
val circle = Circle()
circle.radius = 1.5f // => circle.setRadius(1.5f)
println(circle.radius) // => circle.getRadius()
Sealed classes (algebraic data types)
// Arithmetic expression
sealed class Expr {
class Const(val number: Double) : Expr()
class Sum(val e1: Expr, val e2: Expr) : Expr()
object NotANumber : Expr()
}
Scala
Huge runtime
Lots of garbage collection
Groovy
Large runtime
Average tooling support
Ceylon
Not much support for Android
Android extensions
btn_go.setText(R.string.go)
btn_go.setOnClickListener { v ->
txt_status.text = "Done"
}
}
Nullability
Production app
Safedome
Converted approx. 95% of the code to Kotlin
Kotlin 1.0.2 (early 2016)
Enabled ProGuard
Used Kotlin features (instead of straight conversion)
Method count
All methods
Method count
Kotlin methods
Lines of code
APK size
Migration guide
Migration guide
Simple process
Add Gradle dependencies (plugin, runtime, etc.)
Start writing .kt files instead of .java ones
No need to migrate everything at once
Kotlin classes can co-exist with Java ones
IntelliJ has a Java-to-Kotlin converter
Not perfect but good start
Works with pasted code
Migration fears
Libraries
Spek, Wasabi, RxKotlin and many more
Documentation
Books, articles, tutorials
Other IDE support
Eclipse
NetBeans
Gradle support
1.0.x track
Bug fixes
Stability improvements
IDE support
1.1.x track
New features
Breaking changes (potentially)
Kotlin EAP 1.1
Coroutines
Type aliases
Bound callable references
Local delegation properties & inline properties
Relaxed rules for sealed classes and data classes
Scripting
Java 7/8 support
JavaScript
Kotlin EAP 1.1 (relevant to Android)
Coroutines
Type aliases
Bound callable references
Local delegation properties & inline properties
Relaxed rules for sealed classes and data classes
Scripting
Java 7/8 support
JavaScript
Summary
Summary
Resources - gouline.net/talks
Documentation - kotlinlang.org/docs/reference
Kotlin Weekly - kotlinweekly.net