Some hard to avoid limitations: Compatibility with past versions of Android • “Compatibility” with some Java 8 features ◦ Virtual Machine Java 6 :( ◦ Not ready to support Java 8
Some hard to avoid limitations: Compatibility with past versions of Android • “Compatibility” with some Java 8 features ◦ Virtual Machine Java 6 :( ◦ Not ready to support Java 8 • Java 8 is limited, compared to other modern languages
Variables can be modified easily ◦ “Race condition” → who is modifying my variable? testing? ◦ We can define everything “final”, but it’s hard to use. ◦ Java framework and libraries use to be mutable. (i.e: Collections and Collections Utils)
Feature supported by Java 8, but in Java 7 there is no support for lambdas and functions as parameters or as a return type ◦ Functional programming ◦ Listeners ◦ Callbacks
Feature supported by Java 8, but in Java 7 there is no support for lambdas and functions as parameters or as a return type ◦ Functional programming ◦ Listeners ◦ Callbacks
Feature supported by Java 8, but in Java 7 there is no support for lambdas and functions as parameters or as a return type ◦ Functional programming ◦ Listeners ◦ Callbacks
◦ Functional programming ◦ Sealed classes • With Kotlin, can be used without third libraries and even using Java 6’s VM • 100% interoperable with Java • Supported by Google for Android
Projects from scratch ◦ Java projects with some Kotlin • Lambda expressions • Inline functions (A new object is not created, the code is replaced at runtime)
Projects from scratch ◦ Java projects with some Kotlin • Lambda expressions • Inline functions (A new object is not created, the code is replaced at runtime) • Null safety
Projects from scratch ◦ Java projects with some Kotlin • Lambda expressions • Inline functions (A new object is not created, the code is replaced at runtime) • Null safety • Smart cast
Projects from scratch ◦ Java projects with some Kotlin • Lambda expressions • Inline functions (A new object is not created, the code is replaced at runtime) • Null safety • Smart cast • String templates
Projects from scratch ◦ Java projects with some Kotlin • Lambda expressions • Inline functions (A new object is not created, the code is replaced at runtime) • Null safety • Smart cast • String templates • Primary constructors
project in the usual way • Browse the plugins (Jetbrains) and install Kotlin plugin • Restart the IDE • Open the MainActivity ◦ Code - Convert Java File to Kotlin File ◦ Magic!
project in the usual way • Browse the plugins (Jetbrains) and install Kotlin plugin • Restart the IDE • Open the MainActivity ◦ Code - Convert Java File to Kotlin File ◦ Magic! • Tools → Kotlin → Configure Kotlin in project → Version ◦ Project full modified (including build.gradle - both, app and project)
project in the usual way • Browse the plugins (Jetbrains) and install Kotlin plugin • Restart the IDE • Open the MainActivity ◦ Code - Convert Java File to Kotlin File ◦ Magic! • Tools → Kotlin → Configure Kotlin in project → Version ◦ Project full modified (including build.gradle - both, app and project) • App build.gradle (add android extension sub-plugin): to access easily view’s elements from Activity ◦ apply plugin: ‘kotlin-android-extension’
Kotlin everything is public • Inheritance • Override as a reserved word rather than an annotation • In function: first name, then the type • Null safety with “?”