Upgrade to Pro — share decks privately, control downloads, hide ads and more …

KotlinConf Report @ca.kt#4

TakuSemba
November 17, 2017

KotlinConf Report @ca.kt#4

TakuSemba

November 17, 2017
Tweet

More Decks by TakuSemba

Other Decks in Technology

Transcript

  1. val i = 10.5 when (i) { in 1..10 ->

    println("in") !in 1..10 -> println("!in") else -> println("else") } // What will it print? // a) in // b) !in // c) else // d) will not compile
  2. open class Named { open var name: String? = null

    get() = field ?: "<unnamed>" } class Person: Named() { override var name: String? = null get() = super.name set(value) { field = "Mr $value" } } val person = Person() person.name = "Anton" println(person.name) // What will it print? // a) Anton // b) Mr Anton // c) <unnamed> // d) null
  3. // What will it print? // a) negative; zero; positive

    // b) negative; zero // c) negative; positive // d) zero; positive fun printNumberSign(num: Int) { if (num < 0) { "negative" } else if (num > 0) { "positive" } else { "zero" }.let { println(it) } } printNumberSign(-2) printNumberSign(0) printNumberSign(2)
  4. // What will it print? // a) 0 // b)

    null // c) will not compile // d) none of the above class Order { private val c: String init { the() c = "" } private fun the() { println(c.length) } } Order()