Slide 1

Slide 1 text

Grzegorz Dyrda Geeky Devs Studio Introduction to Kotlin

Slide 2

Slide 2 text

Grzegorz Dyrda Geeky Devs Studio Introduction to Kotlin

Slide 3

Slide 3 text

Grzegorz Dyrda Geeky Devs Studio Introduction to Kotlin

Slide 4

Slide 4 text

What is Kotlin? • Statically typed programming language for JVM, Android and the browser - developer since 2010 by JetBrains • Similar to Java, but free of its legacy problems and limitations • Can be freely mixed with Java (6+), existing codebase, ecosystem (Maven, Gradle), libraries etc. • Benefits: improved safety (no NPEs), increased readability (minimum boilerplate), added missing features • Easy learning curve (similar to Java/C#/JS), modern & fun!

Slide 5

Slide 5 text

• Null safety • No checked exceptions • Extension functions • Higher-order functions • Function types & lambdas • Default & named arguments • Properties • Type inference • Operator overloading • Smart casts Kotlin features

Slide 6

Slide 6 text

• Null safety • No checked exceptions • Extension functions • Higher-order functions • Function types & lambdas • Default & named arguments • Properties • Type inference • Operator overloading • Smart casts • Data classes • Immutable collections • Enhanced switch-case • String interpolation • Ranges • Inline functions • Infix notation • Tail recursion • Coroutines (async/await) • Great Standard Library Kotlin features

Slide 7

Slide 7 text

• Null safety • No checked exceptions • Extension functions • Higher-order functions • Function types & lambdas • Default & named arguments • Properties • Type inference • Operator overloading • Smart casts • Data classes • Immutable collections • Enhanced switch-case • String interpolation • Ranges • Inline functions • Infix notation • Tail recursion • Coroutines (async/await) • Great Standard Library • Sealed classes • Delegated & lazy properties • Class delegation • Singletons • Nested functions • Object decomposition • Top-level functions • Reified generics • Raw Strings • And more… + 100% Java interoperable + Compiles to Java 6 bytecode + Syntax similar to Java/C#/JavaScript + Great tooling + Great community + Rapid development Kotlin features

Slide 8

Slide 8 text

No content

Slide 9

Slide 9 text

Basic syntax

Slide 10

Slide 10 text

Functions // Java public int sum(int a, int b) {
 return a + b;
 }} // Kotlin public fun sum(a: Int, b: Int): Int {
 return a + b
 }}

Slide 11

Slide 11 text

// Java public int sum(int a, int b) {
 return a + b;
 }} // Kotlin public fun sum(a: Int, b: Int): Int {
 return a + b
 }} Functions

Slide 12

Slide 12 text

// Java public int sum(int a, int b) {
 return a + b;
 }} // Kotlin public fun sum(a: Int, b: Int): Int {
 return a + b
 }} Functions

Slide 13

Slide 13 text

// Java public int sum(int a, int b) {
 return a + b;
 }} // Kotlin public fun sum(a: Int, b: Int): Int {
 return a + b
 }} Functions

Slide 14

Slide 14 text

// Java public int sum(int a, int b) {
 return a + b;
 }} // Kotlin public fun sum(a: Int, b: Int): Int {
 return a + b
 }} Functions

Slide 15

Slide 15 text

// Java public int sum(int a, int b) {
 return a + b;
 }} // Kotlin public fun sum(a: Int, b: Int): Int {
 return a + b
 }} Functions

Slide 16

Slide 16 text

// Java public int sum(int a, int b) {
 return a + b;
 }} // Kotlin public fun sum(a: Int, b: Int): Int = a + b Functions

Slide 17

Slide 17 text

// Java public int sum(int a, int b) {
 return a + b;
 }} // Kotlin public fun sum(a: Int, b: Int) = a + b Functions

Slide 18

Slide 18 text

Function Arguments // Java
 public void repeat(String str, int count, String separator) {
 ...
 }} repeat("abc", 5, "");

Slide 19

Slide 19 text

// Java
 public void repeat(String str, int count, String separator) {
 ...
 }} repeat("abc", 5, ""); // Kotlin
 fun repeat(str: String, count: Int, separator: String) {
 ...
 }} repeat("abc", 5, "")) Function Arguments

Slide 20

Slide 20 text

// Kotlin
 fun repeat(str: String, count: Int = 3, separator: String = "") {
 ...
 }} repeat("abc", 5, "")) // Java
 public void repeat(String str, int count, String separator) {
 ...
 }} repeat("abc", 5, ""); Function Arguments

Slide 21

Slide 21 text

// Kotlin
 fun repeat(str: String, count: Int = 3, separator: String = "") {
 ...
 }} repeat("abc", 5)) // Java
 public void repeat(String str, int count, String separator) {
 ...
 }} repeat("abc", 5, ""); Function Arguments

Slide 22

Slide 22 text

// Kotlin
 fun repeat(str: String, count: Int = 3, separator: String = "") {
 ...
 }} 
 repeat("abc", count = 5)) // Java
 public void repeat(String str, int count, String separator) {
 ...
 }} repeat("abc", 5, ""); Function Arguments

Slide 23

Slide 23 text

// Kotlin
 fun repeat(str: String, count: Int = 3, separator: String = "") {
 ...
 }} 
 repeat("abc", count = 5, separator = ",")) // Java
 public void repeat(String str, int count, String separator) {
 ...
 }} repeat("abc", 5, ""); Function Arguments

Slide 24

Slide 24 text

// Kotlin
 fun repeat(str: String, count: Int = 3, separator: String = "") {
 ...
 }} 
 repeat("abc", separator = ",")) // Java
 public void repeat(String str, int count, String separator) {
 ...
 }} repeat("abc", 5, ""); Function Arguments

Slide 25

Slide 25 text

Variables // Java int a = 1;
 String b = "xyz"; // Kotlin val a: Int = 1
 val b: String = "xyz"

Slide 26

Slide 26 text

// Java int a = 1;
 String b = "xyz"; // Kotlin val a: Int = 1
 val b: String = "xyz" Variables

Slide 27

Slide 27 text

// Java int a = 1;
 String b = "xyz"; // Kotlin val a: Int = 1
 val b: String = "xyz" Variables

Slide 28

Slide 28 text

// Java int a = 1;
 String b = "xyz"; // Kotlin val a: Int = 1
 val b: String = "xyz" Variables

Slide 29

Slide 29 text

// Kotlin val a = 1 // Inferred type is Int
 val b = "xyz" // Inferred type is String // Java int a = 1;
 String b = "xyz"; Variables

Slide 30

Slide 30 text

mutability

Slide 31

Slide 31 text

(Im)mutability // Assign-once (read-only) variable val x = 1
 x = 2 // Compile-time error // Mutable variable var y = 5
 y = 10 // OK


Slide 32

Slide 32 text

(Im)mutability // Assign-once (read-only) variable val x = 1
 x = 2 // Compile-time error // Mutable variable var y = 5
 y = 10 // OK
 // Always start with immutable "val" // Change to "var" only when necessary

Slide 33

Slide 33 text

Null safety

Slide 34

Slide 34 text

Null safety var str: String = "xyz"
 str = null // ???


Slide 35

Slide 35 text

Null safety var str: String = "xyz"
 str = null // Compile-time error

Slide 36

Slide 36 text

Null safety var str: String? = "xyz"
 str = null // OK

Slide 37

Slide 37 text

Null safety fun getLength(str: String): Int? {
 return str.length // ???
 }}


Slide 38

Slide 38 text

Null safety fun getLength(str: String): Int? {
 return str.length // OK
 }}

Slide 39

Slide 39 text

Null safety fun getLength(str: String?): Int? {
 return str.length // ???
 }}

Slide 40

Slide 40 text

Null safety fun getLength(str: String?): Int? {
 return str.length // Compile-time error
 }}

Slide 41

Slide 41 text

Null safety fun getLength(str: String?): Int? {
 if (str != null) {
 return str.length
 }
 return 0 }}

Slide 42

Slide 42 text

Null safety fun getLength(str: String?): Int? {
 if (str != null) {
 return str.length // <-- Smart cast
 }
 return 0 }}

Slide 43

Slide 43 text

Null safety fun getLength(str: String?): Int? {}
 return str?.length }}

Slide 44

Slide 44 text

Null safety fun getLength(str: String?): Int {}
 return str?.length ?: 0 }}

Slide 45

Slide 45 text

Null safety // Java
 public ZipCode getZipCode(User user) {
 if (user != null) {
 if (user.getAddress() != null) {
 return user.getAddress().getZipCode();
 }}
 }}
 return null;
 }}
 // Kotlin fun getZipCode(user: User?): ZipCode? {}
 return user?.address?.zipCode }}

Slide 46

Slide 46 text

Null safety // Java
 public ZipCode getZipCode(User user) {
 if (user != null) {
 if (user.getAddress() != null) {
 return user.getAddress().getZipCode();
 }}
 }}
 return null;
 }}
 // Kotlin fun getZipCode(user: User?) = user?.address?.zipCode

Slide 47

Slide 47 text

String Interpolation override fun toString(): String {
 return "Song{id=" +
 id +
 ", title='" +
 title +
 "', author='" +
 author +
 "'}"
 }}

Slide 48

Slide 48 text

override fun toString(): String {
 return "Song{id=$id, title='$title', author='$author'}"
 }} String Interpolation

Slide 49

Slide 49 text

override fun toString() = "Song{id=$id, title='$title', author='$author'}" String Interpolation

Slide 50

Slide 50 text

Classes // Java
 public class User {
 
 }}

Slide 51

Slide 51 text

Classes // Java
 public class User {
 
 String firstName;
 String lastName;
 int age;
 
 }}

Slide 52

Slide 52 text

Classes // Java
 public class User {
 
 String firstName;
 String lastName;
 int age; public User(String firstName, String lastName, int age) {
 this.firstName = firstName;
 this.lastName = lastName;
 this.age = age;
 }}
 
 }}

Slide 53

Slide 53 text

Classes // Java
 public class User {
 
 String firstName;
 String lastName;
 int age; public User(String firstName, String lastName, int age) {
 this.firstName = firstName;
 this.lastName = lastName;
 this.age = age;
 }}
 
 public String getFirstName() {
 return firstName;
 }}
 
 public void setFirstName(String firstName) {
 this.firstName = firstName;
 }}
 
 public String getLastName() {
 return lastName;
 }}
 
 public void setLastName(String lastName) {
 this.lastName = lastName;
 }}
 
 public int getAge() {
 return age;
 }}
 
 public void setAge(int age) {
 this.age = age;
 }}
 
 }}

Slide 54

Slide 54 text

Classes // Java
 public class User {
 
 String firstName;
 String lastName;
 int age; public User(String firstName, String lastName, int age) {
 this.firstName = firstName;
 this.lastName = lastName;
 this.age = age;
 }
 
 public String getFirstName() {
 return firstName;
 }
 
 public void setFirstName(String firstName) {
 this.firstName = firstName;
 }
 
 public String getLastName() {
 return lastName;
 }
 
 public void setLastName(String lastName) {
 this.lastName = lastName;
 }
 
 public int getAge() {
 return age;
 }
 
 public void setAge(int age) {
 this.age = age;
 }
 
 @Override
 public boolean equals(Object o) {
 if (this == o) return true;
 if (o == null || getClass() != o.getClass()) return false;
 
 User user = (User) o;
 
 if (age != user.age) return false;
 if (firstName != null ? !firstName.equals(user.firstName) : user.firstName != null)
 return false;
 return lastName != null ? lastName.equals(user.lastName) : user.lastName == null;
 
 }
 
 @Override
 public int hashCode() {
 int result = firstName != null ? firstName.hashCode() : 0;
 result = 31 * result + (lastName != null ? lastName.hashCode() : 0);
 result = 31 * result + age;
 return result;
 }
 
 @Override
 public String toString() {
 return "User{" +
 "firstName='" + firstName + '\'' +
 ", lastName='" + lastName + '\'' +
 ", age=" + age +
 '}';
 }
 
 }} 53 lines of code!

Slide 55

Slide 55 text

Classes // Java
 public class User {
 
 String firstName;
 String lastName;
 int age; public User(String firstName, String lastName, int age) {
 this.firstName = firstName;
 this.lastName = lastName;
 this.age = age;
 }
 
 public String getFirstName() {
 return firstName;
 }
 
 public void setFirstName(String firstName) {
 this.firstName = firstName;
 }
 
 public String getLastName() {
 return lastName;
 }
 
 public void setLastName(String lastName) {
 this.lastName = lastName;
 }
 
 public int getAge() {
 return age;
 }
 
 public void setAge(int age) {
 this.age = age;
 }
 
 @Override
 public boolean equals(Object o) {
 if (this == o) return true;
 if (o == null || getClass() != o.getClass()) return false;
 
 User user = (User) o;
 
 if (age != user.age) return false;
 if (firstName != null ? !firstName.equals(user.firstName) : user.firstName != null)
 return false;
 return lastName != null ? lastName.equals(user.lastName) : user.lastName == null;
 
 }
 
 @Override
 public int hashCode() {
 int result = firstName != null ? firstName.hashCode() : 0;
 result = 31 * result + (lastName != null ? lastName.hashCode() : 0);
 result = 31 * result + age;
 return result;
 }
 
 @Override
 public String toString() {
 return "User{" +
 "firstName='" + firstName + '\'' +
 ", lastName='" + lastName + '\'' +
 ", age=" + age +
 '}';
 }
 
 }}

Slide 56

Slide 56 text

Classes // Kotlin
 class User {
 
 var firstName: String?
 var lastName: String?
 var age: Int
 
 constructor(firstName: String?, lastName: String?, age: Int) {
 this.firstName = firstName
 this.lastName = lastName
 this.age = age
 }}
 
 override fun equals(other: Any?): Boolean {
 if (this === other) return true
 if (other?.javaClass != javaClass) return false
 
 other as User
 
 if (firstName != other.firstName) return false
 if (lastName != other.lastName) return false
 if (age != other.age) return false
 
 return true
 }}
 
 override fun hashCode(): Int {
 var result = firstName?.hashCode() ?: 0
 result = 31 * result + (lastName?.hashCode() ?: 0)
 result = 31 * result + age
 return result
 }}
 
 override fun toString(): String {
 return "User{" +
 "firstName='" + firstName + '\'' +
 ", lastName='" + lastName + '\'' +
 ", age=" + age +
 '}'
 }}
 
 }}

Slide 57

Slide 57 text

Classes // Kotlin
 class User {
 
 var firstName: String?
 var lastName: String?
 var age: Int
 
 constructor(firstName: String?, lastName: String?, age: Int) {
 this.firstName = firstName
 this.lastName = lastName
 this.age = age
 }}
 
 override fun equals(other: Any?): Boolean {
 if (this === other) return true
 if (other?.javaClass != javaClass) return false
 
 other as User
 
 if (firstName != other.firstName) return false
 if (lastName != other.lastName) return false
 if (age != other.age) return false
 
 return true
 }}
 
 override fun hashCode(): Int {
 var result = firstName?.hashCode() ?: 0
 result = 31 * result + (lastName?.hashCode() ?: 0)
 result = 31 * result + age
 return result
 }}
 
 override fun toString(): String {
 return "User{" +
 "firstName='" + firstName + '\'' +
 ", lastName='" + lastName + '\'' +
 ", age=" + age +
 '}'
 }}
 
 }}

Slide 58

Slide 58 text

Classes // Kotlin
 class User {
 
 var firstName: String?
 var lastName: String?
 var age: Int
 
 constructor(firstName: String?, lastName: String?, age: Int) {
 this.firstName = firstName
 this.lastName = lastName
 this.age = age
 }}
 
 override fun equals(other: Any?): Boolean {
 if (this === other) return true
 if (other?.javaClass != javaClass) return false
 
 other as User
 
 if (firstName != other.firstName) return false
 if (lastName != other.lastName) return false
 if (age != other.age) return false
 
 return true
 }}
 
 override fun hashCode(): Int {
 var result = firstName?.hashCode() ?: 0
 result = 31 * result + (lastName?.hashCode() ?: 0)
 result = 31 * result + age
 return result
 }}
 
 override fun toString() = "User{firstName='$firstName', lastName='$lastName', age=$age}"
 
 }}

Slide 59

Slide 59 text

Classes // Kotlin
 class User(var firstName: String?, var lastName: String?, var age: Int) {
 
 override fun equals(other: Any?): Boolean {
 if (this === other) return true
 if (other?.javaClass != javaClass) return false
 
 other as User
 
 if (firstName != other.firstName) return false
 if (lastName != other.lastName) return false
 if (age != other.age) return false
 
 return true
 }}
 
 override fun hashCode(): Int {
 var result = firstName?.hashCode() ?: 0
 result = 31 * result + (lastName?.hashCode() ?: 0)
 result = 31 * result + age
 return result
 }}
 
 override fun toString() = "User{firstName='$firstName', lastName='$lastName', age=$age}"
 
 }}

Slide 60

Slide 60 text

Data Classes // Kotlin
 data class User(var firstName: String?, var lastName: String?, var age: Int)

Slide 61

Slide 61 text

Data Classes // Kotlin
 data class User(var firstName: String?, var lastName: String?, var age: Int)
 
 // data = equals() + hashCode() + toString() + copy() 1 line in Kotlin vs 53 lines in Java

Slide 62

Slide 62 text

Multiple items in file // Models.kt
 data class User(val firstName: String, val lastName: String, val age: Int)
 data class Address(val street: String, val zipCode: ZipCode)
 data class ZipCode(val prefix: String, val postfix: String)


Slide 63

Slide 63 text

Properties class User {
 var firstName: String? = ...
 var lastName: String = ...
 val age: Int = ...
 }}

Slide 64

Slide 64 text

Properties class User {
 var firstName: String? = ... // mutable (getter/setter)
 var lastName: String = ... // mutable
 val age: Int = ... // read-only (getter only)
 }}

Slide 65

Slide 65 text

Properties class User {
 var firstName: String? = ... // mutable (getter/setter)
 var lastName: String = ... // mutable
 val age: Int = ... // read-only (getter only)
 }}
 // Use them as fields
 fun test() {
 val user = User()
 user.firstName = “Grzegorz” // setter is called
 print("firstName = ${user.firstName}") // getter is called
 }}

Slide 66

Slide 66 text

Properties class User {
 var firstName: String? = ""
 var lastName: String = ""
 val age: Int = 0
 }}

Slide 67

Slide 67 text

Properties class User {
 var firstName: String? = ""
 get() {
 return "abc"
 }}
 
 var lastName: String = ""
 val age: Int = 0
 }}

Slide 68

Slide 68 text

Properties class User {
 var firstName: String? = ""
 get() = "abc"
 
 var lastName: String = ""
 val age: Int = 0
 }}

Slide 69

Slide 69 text

Properties class User {
 var firstName: String? = ""
 get() = "abc"
 set(value) {
 field = value + "xyz"
 }}
 
 var lastName: String = ""
 val age: Int = 0
 }}

Slide 70

Slide 70 text

Top-level functions // MyFunctions.kt
 package com.kotlin.demo
 
 fun warning(msg: String) {
 print("WARNING: $msg")
 } // Demo.kt
 import com.kotlin.demo.warning
 
 fun doSomething() {
 warning("I'm warning you!")
 }

Slide 71

Slide 71 text

Top-level functions // MyFunctions.kt
 package com.kotlin.demo
 
 fun warning(msg: String) {
 print("WARNING: $msg”) // package kotlin.io
 } // Demo.kt
 import com.kotlin.demo.warning
 
 fun doSomething() {
 warning("I'm warning you!")
 }

Slide 72

Slide 72 text

Extensions // Java
 public class StringUtils {
 public static String toCamelCase(String str) { return str.replaceAll...
 } }

Slide 73

Slide 73 text

Extensions // Java
 public class StringUtils {
 public static String toCamelCase(String str) { return str.replaceAll...
 }} }} 
 
 
 String camelStr = StringUtils.toCamelCase("lorem ipsum");

Slide 74

Slide 74 text

Extensions // Java
 public class StringUtils {
 public static String toCamelCase(String str) { return str.replaceAll...
 }} }} 
 
 import static com.demo.StringUtils.toCamelCase;
 
 String camelStr = toCamelCase("lorem ipsum");


Slide 75

Slide 75 text

Extensions // Java
 public class StringUtils {
 public static String toCamelCase(String str) { return str.replaceAll...
 }} }} 
 
 import static com.demo.StringUtils.toCamelCase;
 
 BufferedReader br = new BufferedReader(new StringReader(toCamelCase("lorem ipsum")));
 ... 
 br.readLine();

Slide 76

Slide 76 text

Extensions // Kotlin fun toCamelCase(str: String): String {
 return str.replace...
 }}

Slide 77

Slide 77 text

Extensions // Kotlin fun String.toCamelCase(str: String): String {
 return str.replace...
 }}

Slide 78

Slide 78 text

Extensions // Kotlin fun String.toCamelCase(): String {
 return this.replace...
 }}

Slide 79

Slide 79 text

Extensions // Kotlin fun String.toCamelCase(): String {
 return this.replace...
 }}
 
 "lorem ipsum".toCamelCase()

Slide 80

Slide 80 text

Extensions // MyFunctions.kt package com.kotlin.demo 
 fun String.toCamelCase(): String {
 return this.replace...
 }}
 
 // Demo.kt
 import com.kotlin.demo.toCamelCase 
 "lorem ipsum".toCamelCase()

Slide 81

Slide 81 text

Extensions // MyFunctions.kt package com.kotlin.demo 
 fun String.toCamelCase(): String {
 return this.replace...
 }}
 
 // Demo.kt
 import com.kotlin.demo.toCamelCase 
 "lorem ipsum".toCamelCase().reader()

Slide 82

Slide 82 text

Extensions // MyFunctions.kt package com.kotlin.demo 
 fun String.toCamelCase(): String {
 return this.replace...
 }}
 
 // Demo.kt
 import com.kotlin.demo.toCamelCase 
 "lorem ipsum".toCamelCase().reader().forEachLine { line ->
 print(line)
 }

Slide 83

Slide 83 text

Extensions 
 
 listOf(1, 2, null, 4, 5)
 .filterNotNull()
 .filter({ it -> it > 2 })
 .forEach({ it ->
 print(it)
 }})

Slide 84

Slide 84 text

Extensions 
 
 listOf(1, 2, null, 4, 5) // factory of immutable lists
 .filterNotNull()
 .filter({ it -> it > 2 })
 .forEach({ it ->
 print(it)
 }})

Slide 85

Slide 85 text

Extensions 
 
 listOf(1, 2, null, 4, 5)
 .filterNotNull() // extension of Iterable
 .filter({ it -> it > 2 }) // extension of Iterable
 .forEach({ it -> // extension of Iterable
 print(it)
 }}) // Why extensions?!

Slide 86

Slide 86 text

Extensions 
 
 listOf(1, 2, null, 4, 5) // What type is it?
 .filterNotNull()
 .filter({ it -> it > 2 })
 .forEach({ it ->
 print(it)
 }})

Slide 87

Slide 87 text

Extensions 
 
 listOf(1, 2, null, 4, 5) // kotlin.collections.List
 .filterNotNull() // covers java.util.List
 .filter({ it -> it > 2 })
 .forEach({ it ->
 print(it)
 }})

Slide 88

Slide 88 text

Extensions 
 
 listOf(1, 2, null, 4, 5)
 .filterNotNull()
 .filter({ it -> it > 2 })
 .forEach({ it ->
 print(it)
 }})

Slide 89

Slide 89 text

Lambdas 
 
 listOf(1, 2, null, 4, 5)
 .filterNotNull()
 .filter({ it -> it > 2 })
 .forEach({ it ->
 print(it)
 }})

Slide 90

Slide 90 text

Lambdas listOf(1, 2, null, 4, 5)
 .filterNotNull()
 .filter() { it -> it > 2 }
 .forEach() { it ->
 print(it)
 }}

Slide 91

Slide 91 text

Lambdas listOf(1, 2, null, 4, 5)
 .filterNotNull()
 .filter { it -> it > 2 }
 .forEach { it ->
 print(it)
 }}

Slide 92

Slide 92 text

Lambdas listOf(1, 2, null, 4, 5)
 .filterNotNull()
 .filter { it > 2 }
 .forEach {
 print(it)
 }}

Slide 93

Slide 93 text

Function Types // Java 8
 Function f1 = (a) -> {
 return String.valueOf(a);
 }; BiFunction f2 = (a, b) -> {
 return String.valueOf(a+b);
 }; // TriFunction... ???

Slide 94

Slide 94 text

Function Types // Java
 public interface TriFunction {
 R apply(T t, U u, V v);
 }} TriFunction f3 = (a, b, c) -> {
 return String.valueOf(a+b+c);
 }; void test(TriFunction func) {
 func.apply(1, 2, 3);
 }}

Slide 95

Slide 95 text

Function Types // Java
 public interface TriFunction {
 R apply(T t, U u, V v);
 }} TriFunction f3 = (a, b, c) -> {
 return String.valueOf(a+b+c);
 }; void test(TriFunction func) {
 func.apply(1, 2, 3);
 }}

Slide 96

Slide 96 text

Function Types // Kotlin 
 val func: (Int, Int, Int) -> String = { a, b, c ->
 (a+b+c).toString()
 }}

Slide 97

Slide 97 text

Function Types // Kotlin 
 val func = { a: Int, b: Int, c: Int ->
 (a+b+c).toString()
 }}

Slide 98

Slide 98 text

Function Types // Kotlin 
 val func = { a: Int, b: Int, c: Int ->
 (a+b+c).toString()
 }} fun functionTest(func: (Int, Int, Int) -> String): Unit {
 func(1, 2, 3)
 }}

Slide 99

Slide 99 text

Function Types // Kotlin 
 val func = { a: Int, b: Int, c: Int ->
 (a+b+c).toString()
 }} fun functionTest(func: (Int, Int, Int) -> String): Unit {
 func(1, 2, 3)
 }}

Slide 100

Slide 100 text

Example - RxJava // Java
 Observable.just("1", "5", "10", "20")
 .map(new Func1() {
 @Override
 public Integer call(String s) {
 return Integer.parseInt(s);
 }}
 })
 .filter(new Func1() {
 @Override
 public Boolean call(Integer integer) {
 return integer > 5;
 }}
 })
 .subscribe(new Action1() {
 @Override
 public void call(Integer integer) {
 System.out.println(integer);
 }}
 });

Slide 101

Slide 101 text

Example - RxJava // Kotlin
 Observable.just("1", "5", "10", "20")
 .map { it.toInt() }
 .filter { it > 10 }
 .subscribe {
 print(it)
 } // Java
 Observable.just("1", "5", "10", "20")
 .map(new Func1() {
 @Override
 public Integer call(String s) {
 return Integer.parseInt(s);
 }}
 })
 .filter(new Func1() {
 @Override
 public Boolean call(Integer integer) {
 return integer > 5;
 }}
 })
 .subscribe(new Action1() {
 @Override
 public void call(Integer integer) {
 System.out.println(integer);
 }}
 });

Slide 102

Slide 102 text

No content

Slide 103

Slide 103 text

Conclusions

Slide 104

Slide 104 text

1. Kotlin Increases Productivity Conclusions

Slide 105

Slide 105 text

1. Kotlin Increases Productivity • Increased readability (minimum boilerplate) • Includes modern features • Improved safety (no NPEs) • Since most barriers are gone, devs can focus on more important things - e.g. system architecture & security

Slide 106

Slide 106 text

2. Kotlin is Ready for Production Conclusions

Slide 107

Slide 107 text

2. Kotlin is Ready for Production • IntelliJ has parts written in Kotlin • JetBrains Rider - C# IDE - is written entirely in Kotlin • 150,000 developers all over the world use Kotlin • Gradle introduced Kotlin support • Spring 5 introduces Kotlin support • Kotlin enters TIOBE top 100

Slide 108

Slide 108 text

How to Start?

Slide 109

Slide 109 text

How to Start? • Home: kotlinlang.org • Great documentation • Online IDE - Hello World, Examples, Advent of Code… • Slack: kotlinlang.slack.com • Great community • My blog: blog.geekydevs.com • Android + Kotlin. How to start? [PL]

Slide 110

Slide 110 text

Thank You

Slide 111

Slide 111 text

Thank You Any questions?

Slide 112

Slide 112 text

Thank You Any questions? Go try Kotlin!