KotlinConf Report @ca.kt#4

A374f41eab3f73c50d8bab0652cb207a?s=47 TakuSemba
November 17, 2017

KotlinConf Report @ca.kt#4

A374f41eab3f73c50d8bab0652cb207a?s=128

TakuSemba

November 17, 2017
Tweet

Transcript

  1. Kotlinconf Report TakuSemba CyberAgent.Inc

  2. @takusemba https://github.com/TakuSemba

  3. Kotlinconf 2017

  4. None
  5. Kotlin Puzzlers

  6. Programing Puzzlers short programs with curious behavior

  7. None
  8. None
  9. First Puzzler

  10. 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
  11. Second Puzzler

  12. 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
  13. Third Puzzler

  14. // 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)
  15. Fourth Puzzler

  16. // 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()
  17. https://github.com/angryziber/kotlin-puzzlers