int age; public Person(String name, int age) { this.name = name; this.age = age; } public String getName() { return name; } public int getAge() { return age; } }
int age; public Person(String name, int age) { this.name = name; this.age = age; } public String getName() { return name; } public int getAge() { return age; } } class Person( val name: String, val age: Int ) person.name person.getName()
average age of employees working in Prague? Working with collections with Lambdas val employees: List<Employee> employees.filter { it.city == City.PRAGUE }.map { it.age }.average() data class Employee( val city: City, val age: Int )
with collections with Lambdas val employees: List<Employee> data class Employee( val city: City, val age: Int ) extension functions employees.filter { it.city == City.PRAGUE }.map { it.age }.average()
(c in 'a'..'z') { append(c) } toString() } The with function with is a function val sb = StringBuilder() sb.appendln("Alphabet: ") for (c in 'a'..'z') { sb.append(c) } sb.toString()
(sb) { this.appendln(“Alphabet: ") for (c in 'a'..'z') { this.append(c) } this.toString() } val sb = StringBuilder() with (sb, { -> this.appendln(“Alphabet: ") for (c in 'a'..'z') { this.append(c) } this.toString() }) lambda is its second argument Lambda with receiver with is a function this is an implicit receiver in the lambda val sb = StringBuilder() with (sb) { appendln("Alphabet: ") for (c in 'a'..'z') { append(c) } toString() } this can be omitted
finally { db.endTransaction() } db.inTransaction { delete("users", "first_name = ?", arrayOf("Jake")) } Inline functions is declared as inline function generated bytecode is similar to
you sure?", message = "Are you really sure?") { positiveButton("Yes") { process() } negativeButton("No") { } }.show() } Are you sure? Are you really sure? No Yes