int age; public Person(String name, int age) { this.name = name; this.age = age; } public String getName() { return name; } public int getAge() { return age; } }
(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
override fun onCreate(savedInstanceState: Bundle?) { Button click_me_button.setOnClickListener { } } } How it works var cachedView: HashMap<Int, View>? fun getCachedViewById(id: Int): View this code is generated by compiler var click_me_button = getCachedViewById(R.id.click_me_button) as Button