Slide 1

Slide 1 text

Kotlin is here Too much fun

Slide 2

Slide 2 text

No content

Slide 3

Slide 3 text

No content

Slide 4

Slide 4 text

No content

Slide 5

Slide 5 text

No content

Slide 6

Slide 6 text

No content

Slide 7

Slide 7 text

.java java compiler .class .jar dex

Slide 8

Slide 8 text

.kt .java java compiler .class .jar dex kotlin compiler

Slide 9

Slide 9 text

class MainActivity : AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_main) }

Slide 10

Slide 10 text

class MainActivity : AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_main) }

Slide 11

Slide 11 text

class MainActivity : AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_main) }

Slide 12

Slide 12 text

class MainActivity : AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_main) }

Slide 13

Slide 13 text

override fun onResume() { super.onResume() mAutofillManager?.registerCallback(mAutofillCallback) } override fun onPause() { super.onPause() mAutofillManager?.unregisterCallback(mAutofillCallback) }

Slide 14

Slide 14 text

No content

Slide 15

Slide 15 text

var index = structure.addChildCount(chidrenSize) val context : Context = request.getContext() Variables

Slide 16

Slide 16 text

var index = structure.addChildCount(chidrenSize) val context : Context = request.getContext() Variables

Slide 17

Slide 17 text

var index = structure.addChildCount(chidrenSize) val context : Context = request.getContext() Variables

Slide 18

Slide 18 text

var index = structure.addChildCount(chidrenSize) val context : Context = request.getContext() Variables var index : Int = structure.addChildCount(chidrenSize)

Slide 19

Slide 19 text

var textValue : String = "" textValue = "alo" var index = structure.addChildCount(chidrenSize) val context : Context = request.getContext() Variables

Slide 20

Slide 20 text

var textValue : String = "" textValue = "alo" var index = structure.addChildCount(chidrenSize) val context : Context = request.getContext() Variables val textValue : String = "" textValue = "alo"

Slide 21

Slide 21 text

var textValue : String = "" textValue = "alo" var index = structure.addChildCount(chidrenSize) val context : Context = request.getContext() Variables val textValue : String = "" textValue = "alo"

Slide 22

Slide 22 text

class SimpleClass Classes/Objects

Slide 23

Slide 23 text

class SimpleClass open class SimpleClass Classes/Objects

Slide 24

Slide 24 text

class SimpleClass open class SimpleClass class SimpleClass : BaseClass() Classes/Objects

Slide 25

Slide 25 text

class SimpleClass open class SimpleClass class SimpleClass : BaseClass() class SimpleClass : SimpleInterface Classes/Objects

Slide 26

Slide 26 text

class SimpleClass open class SimpleClass class SimpleClass : BaseClass() class SimpleClass : SimpleInterface object SimpleClass Classes/Objects

Slide 27

Slide 27 text

class SimpleClass(value: String) Classes/Objects

Slide 28

Slide 28 text

class SimpleClass(value: String) Classes/Objects class Team { val player : String var goals : Int }

Slide 29

Slide 29 text

class SimpleClass(value: String) Classes/Objects class Team { val player : String var goals : Int }

Slide 30

Slide 30 text

class SimpleClass(value: String) Classes/Objects class Team { val player : String = “Rivaldo” var goals : Int = 0 }

Slide 31

Slide 31 text

class SimpleClass(value: String) Classes/Objects val myPlayer = Team(“Rivaldo”,0) class Team(player: String, goals: Int)

Slide 32

Slide 32 text

class SimpleClass(value: String) Classes/Objects val myPlayer = Team(“Rivaldo”,0) class Team(player: String) { var goals: Int = 0 } class Team(player: String, goals: Int)

Slide 33

Slide 33 text

class SimpleClass(value: String) Classes/Objects val myPlayer = Team(“Rivaldo”,0) class Team(player: String) { var goals: Int = 0 } val myPlayer = Team("Rivaldo") myPlayer.goals = 3 class Team(player: String, goals: Int)

Slide 34

Slide 34 text

Classes/Objects var goals: Int = 0 set(value) { if (goals > 5) { log(“$player has scored multiple goals") field = value } }

Slide 35

Slide 35 text

Classes/Objects var goals: Int = 0 set(value) { if (goals > 5) { log(“$player has scored multiple goals") field = value } } val isEmpty get() = this.size == 0

Slide 36

Slide 36 text

class SimpleClass(value: String){ init { log() } } Classes/Objects

Slide 37

Slide 37 text

class SimpleClass(value: String){ init { log() } } Classes/Objects class Button : View { constructor(ctx: Context) : super(ctx) constructor(ctx: Context, attr: AttributeSet) : super(ctx, attr) }

Slide 38

Slide 38 text

Classes/Objects data class Team (val name : String, val goals : Int)

Slide 39

Slide 39 text

Classes/Objects data class Team (val name : String, val goals : Int) hashCode - toString - equals

Slide 40

Slide 40 text

Classes/Objects class A { companion object { fun bar() { println("Companion Object") } } } data class Team (val name : String, val goals : Int) hashCode - toString - equals

Slide 41

Slide 41 text

Classes/Objects class A { companion object { fun bar() { println("Companion Object") } } } data class Team (val name : String, val goals : Int) hashCode - toString - equals A.bar()

Slide 42

Slide 42 text

Smart Casts public void printTypeProperty(Object object) { if (object instanceof String) { System.out.print(((String) object).isEmpty()); } else if (object instanceof Integer){ System.out.print(((Integer) object).intValue()); } else if (object instanceof Boolean){ System.out.print(((Boolean) object).booleanValue()); } }

Slide 43

Slide 43 text

fun printTypeProperty(any: Any) { if (any is String) { println(any.length) } else if (any is Int) { println(any.plus(1)) } else if (any is Boolean) { println(any.not()) } } Smart Casts public void printTypeProperty(Object object) { if (object instanceof String) { System.out.print(((String) object).isEmpty()); } else if (object instanceof Integer){ System.out.print(((Integer) object).intValue()); } else if (object instanceof Boolean){ System.out.print(((Boolean) object).booleanValue()); } }

Slide 44

Slide 44 text

fun printTypeProperty(any: Any) { if (any is String) { println(any.length) } else if (any is Int) { println(any.plus(1)) } else if (any is Boolean) { println(any.not()) } } Smart Casts public void printTypeProperty(Object object) { if (object instanceof String) { System.out.print(((String) object).isEmpty()); } else if (object instanceof Integer){ System.out.print(((Integer) object).intValue()); } else if (object instanceof Boolean){ System.out.print(((Boolean) object).booleanValue()); } }

Slide 45

Slide 45 text

sealed class Expr data class Const(val number: Double) : Expr() data class Sum(val e1: Expr, val e2: Expr) : Expr() object NotANumber : Expr() Sealed Classes

Slide 46

Slide 46 text

sealed class Expr data class Const(val number: Double) : Expr() data class Sum(val e1: Expr, val e2: Expr) : Expr() object NotANumber : Expr() Sealed Classes

Slide 47

Slide 47 text

sealed class Expr data class Const(val number: Double) : Expr() data class Sum(val e1: Expr, val e2: Expr) : Expr() object NotANumber : Expr() Sealed Classes

Slide 48

Slide 48 text

sealed class Expr data class Const(val number: Double) : Expr() data class Sum(val e1: Expr, val e2: Expr) : Expr() object NotANumber : Expr() fun eval(expr: Expr): Double = when(expr) { is Const -> expr.number is Sum -> eval(expr.e1) + eval(expr.e2) NotANumber -> Double.NaN } Sealed Classes

Slide 49

Slide 49 text

sealed class Expr data class Const(val number: Double) : Expr() data class Sum(val e1: Expr, val e2: Expr) : Expr() object NotANumber : Expr() fun eval(expr: Expr): Double = when(expr) { is Const -> expr.number is Sum -> eval(expr.e1) + eval(expr.e2) NotANumber -> Double.NaN } Sealed Classes

Slide 50

Slide 50 text

sealed class Expr data class Const(val number: Double) : Expr() data class Sum(val e1: Expr, val e2: Expr) : Expr() object NotANumber : Expr() fun eval(expr: Expr): Double = when(expr) { is Const -> expr.number is Sum -> eval(expr.e1) + eval(expr.e2) NotANumber -> Double.NaN } Sealed Classes

Slide 51

Slide 51 text

Interfaces class SimpleClass : SimpleInterface

Slide 52

Slide 52 text

interface SimpleInterface { fun doSomething() } Interfaces class SimpleClass : SimpleInterface

Slide 53

Slide 53 text

interface SimpleInterface { fun doSomething() } interface SimpleInterface { fun doSomething() fun doAnotherThing() = println("default") } Interfaces class SimpleClass : SimpleInterface

Slide 54

Slide 54 text

int strLen(String s){ return s.length(); } Nullability

Slide 55

Slide 55 text

fun strLen(s: String) = s.length int strLen(String s){ return s.length(); } Nullability

Slide 56

Slide 56 text

fun strLen(s: String) = s.length int strLen(String s){ return s.length(); } fun strLen(s: String?) = … Nullability

Slide 57

Slide 57 text

fun strLen(s: String) = s.length int strLen(String s){ return s.length(); } fun strLen(s: String?) = … fun strLen(s: String?): Int = if (s != null) s.length else 0 Nullability

Slide 58

Slide 58 text

fun toUpperCase(s: String?): String? Nullability

Slide 59

Slide 59 text

fun toUpperCase(s: String?): String? fun toUpperCase(s: String?): String? = s?.toUpperCase() Nullability

Slide 60

Slide 60 text

fun toUpperCase(s: String?): String? fun toUpperCase(s: String?): String? = s?.toUpperCase() Nullability

Slide 61

Slide 61 text

fun toUpperCase(s: String?): String? fun toUpperCase(s: String?): String? = s?.toUpperCase() fun length(s: String?): Int Nullability

Slide 62

Slide 62 text

fun toUpperCase(s: String?): String? fun toUpperCase(s: String?): String? = s?.toUpperCase() fun length(s: String?): Int fun length(s: String?): Int = s?.length ?: 0 Nullability

Slide 63

Slide 63 text

fun toUpperCase(s: String?): String? fun toUpperCase(s: String?): String? = s?.toUpperCase() fun length(s: String?): Int fun length(s: String?): Int = s?.length ?: 0 Nullability

Slide 64

Slide 64 text

fun toUpperCase(s: String?): String? fun toUpperCase(s: String?): String? = s?.toUpperCase() fun length(s: String?): Int fun length(s: String?): Int = s?.length ?: 0 Nullability

Slide 65

Slide 65 text

this as? PageObjectKt Nullability

Slide 66

Slide 66 text

this as? PageObjectKt Nullability email?.let { email -> sendEmailTo()}

Slide 67

Slide 67 text

fun max(a: Int, b: Int): Int { return if (a > b) a else b } Functions

Slide 68

Slide 68 text

fun max(a: Int, b: Int): Int { return if (a > b) a else b } Functions

Slide 69

Slide 69 text

fun max(a: Int, b: Int): Int { return if (a > b) a else b } Functions

Slide 70

Slide 70 text

fun max(a: Int, b: Int): Int { return if (a > b) a else b } Functions

Slide 71

Slide 71 text

fun createPlayer(name: String, lastName: String, nickName: String?, city: String?) { Functions - Named Arguments

Slide 72

Slide 72 text

fun createPlayer(name: String, lastName: String, nickName: String?, city: String?) { createPlayer("Inaki", "Villar", null, null) Functions - Named Arguments

Slide 73

Slide 73 text

fun createPlayer(name: String, lastName: String, nickName: String?, city: String?) { createPlayer("Inaki", "Villar", null, null) createPlayer("Inaki", "Villar", nickName = null, city = null) Functions - Named Arguments

Slide 74

Slide 74 text

fun createPlayer(name: String, lastName: String, nickName: String = “", city: String = "Cebu") Functions - Default Arguments

Slide 75

Slide 75 text

fun createPlayer(name: String, lastName: String, nickName: String = “", city: String = "Cebu") createPlayer("Inaki", "Villar") Functions - Default Arguments createPlayer("Inaki", "Villar", "Nine")

Slide 76

Slide 76 text

fun lengthIsGreaterThanFive(s : String) = s.length > 5 val va = "myVeryLongString" val isGreaterThanFive = lengthIsGreaterThanFive(va) Extension Functions

Slide 77

Slide 77 text

fun lengthIsGreaterThanFive(s : String) = s.length > 5 val va = "myVeryLongString" val isGreaterThanFive = lengthIsGreaterThanFive(va) Extension Functions fun String.lengthIsGreaterThanFive() = this.length > 5

Slide 78

Slide 78 text

fun lengthIsGreaterThanFive(s : String) = s.length > 5 val va = "myVeryLongString" val isGreaterThanFive = lengthIsGreaterThanFive(va) Extension Functions fun String.lengthIsGreaterThanFive() = this.length > 5

Slide 79

Slide 79 text

fun lengthIsGreaterThanFive(s : String) = s.length > 5 val va = "myVeryLongString" val isGreaterThanFive = lengthIsGreaterThanFive(va) val va = "myVeryLongString" val isGreaterThanFive = va.lengthIsGreaterThanFive() Extension Functions fun String.lengthIsGreaterThanFive() = this.length > 5

Slide 80

Slide 80 text

Infix Functions infix fun Int.minus(value: Int) = this - value

Slide 81

Slide 81 text

Infix Functions infix fun Int.minus(value: Int) = this - value

Slide 82

Slide 82 text

Infix Functions infix fun Int.minus(value: Int) = this - value val result = 4 minus 2

Slide 83

Slide 83 text

Infix Functions infix fun Int.minus(value: Int) = this - value val result = 4 minus 2

Slide 84

Slide 84 text

Infix Functions infix fun Int.minus(value: Int) = this - value val result = 4 minus 2 4.minus(2)

Slide 85

Slide 85 text

Infix Functions infix fun Int.minus(value: Int) = this - value val result = 4 minus 2 infix fun String.repeat(times: Int) = { var result = "" for (i in 1..times) { result += this } }

Slide 86

Slide 86 text

Infix Functions infix fun Int.minus(value: Int) = this - value val result = 4 minus 2 infix fun String.repeat(times: Int) = { var result = "" for (i in 1..times) { result += this } }

Slide 87

Slide 87 text

Infix Functions infix fun Int.minus(value: Int) = this - value val result = 4 minus 2 infix fun String.repeat(times: Int) = { var result = "" for (i in 1..times) { result += this } } val multipleA = "a" repeat 10

Slide 88

Slide 88 text

Lambdas

Slide 89

Slide 89 text

buttonSend.setOnClickListener(new View.OnClickListener(){ @Override public void onClick(View v){ send(); } }); Lambdas

Slide 90

Slide 90 text

buttonSend.setOnClickListener(new View.OnClickListener(){ @Override public void onClick(View v){ send(); } }); buttonSend.setOnClickListener(object :OnClickListener{ override fun onClick(view : View){ send(); } }) Lambdas

Slide 91

Slide 91 text

buttonSend.setOnClickListener(new View.OnClickListener(){ @Override public void onClick(View v){ send(); } }); buttonSend.setOnClickListener(object :OnClickListener{ override fun onClick(view : View){ send(); } }) buttonSend.setOnClickListener(View.OnClickListener { view : View -> doSomething() }) Lambdas

Slide 92

Slide 92 text

{ x : Int, y: Int -> x + y } Lambdas

Slide 93

Slide 93 text

{ x : Int, y: Int -> x + y } Lambdas

Slide 94

Slide 94 text

{ x : Int, y: Int -> x + y } Lambdas

Slide 95

Slide 95 text

data class Team (val name : String, val goals : Int) val myLeague = listOf(Team("Sakuvic", 12), Team("Rivaldo",10)) Lambdas

Slide 96

Slide 96 text

data class Team (val name : String, val goals : Int) val myLeague = listOf(Team("Sakuvic", 12), Team("Rivaldo",10)) myLeague.maxBy({ p: Team -> p.goals }) Lambdas

Slide 97

Slide 97 text

data class Team (val name : String, val goals : Int) val myLeague = listOf(Team("Sakuvic", 12), Team("Rivaldo",10)) myLeague.maxBy({ p: Team -> p.goals }) myLeague.maxBy { p: Team -> p.goals } Lambdas

Slide 98

Slide 98 text

myLeague.maxBy { it.goals } data class Team (val name : String, val goals : Int) val myLeague = listOf(Team("Sakuvic", 12), Team("Rivaldo",10)) myLeague.maxBy({ p: Team -> p.goals }) myLeague.maxBy { p: Team -> p.goals } Lambdas

Slide 99

Slide 99 text

No content

Slide 100

Slide 100 text

private val mOnNavigationItemSelectedListener = BottomNavigationView.OnNavigationItemSelectedListener { item -> when (item.itemId) { R.id.navigation_home -> { message.setText(R.string.title_home) return@OnNavigationItemSelectedListener true } R.id.navigation_dashboard -> { message.setText(R.string.title_dashboard) return@OnNavigationItemSelectedListener true } R.id.navigation_notifications -> { message.setText(R.string.title_notifications) return@OnNavigationItemSelectedListener true } } false Future is here

Slide 101

Slide 101 text

Much more Type System Delegation High Order Functions & FP Operator Generics DSL

Slide 102

Slide 102 text

No content

Slide 103

Slide 103 text

[email protected] @inyaki_mwc Thanks