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

Watashi ni Kotlin ga maiorita

Watashi ni Kotlin ga maiorita

きりみん

March 19, 2019
Tweet

More Decks by きりみん

Other Decks in Programming

Transcript

  1. Nullڐ༰ܕͱNullඇڐ༰ܕ var hoge: String = null // ίϯύΠϧΤϥʔ var hoge:

    String = "hoge" hoge = null // ίϯύΠϧΤϥʔ -------------------------------------------- var fuga: String? = null // OK var fuga: String? = "fuga" fuga = null // OK
  2. NullΛѻ͏ͨΊͷศརͳؔ਺ var hoge: String? = "hoge" hoge.size // ίϯύΠϧΤϥʔ hoge?.size

    // hoge͕nullͳΒ͹࣮ߦ͞Εͳ͍ hoge?.size ?: return // hoge͕nullͳΒreturn val size = hoge?.size ?: 0 // hoge͕nullͳΒ0Λ୅ೖ hoge?.let { // hoge͕nullͳΒ࣮ߦ͞Εͳ͍ println(it.size) } hoge.isNullOrEmpty() // null΋͘͠͸ۭจࣈͳΒtrue
  3. valએݴͱvarએݴ val hoge: String = "hoge" hoge = "fuga" //

    ίϯύΠϧΤϥʔ -------------------------------------------- var hoge: String = "hoge" hoge = "fuga" // OK
  4. JavaΑΓ΋ؾܰʹ͔ͭ͑Δศརͳ Ϧετૢ࡞ؔ਺ val list = listof("a", "bb", "ccc") val sizeList

    = list.map { str -> str.size } // sizeList = { 1, 2, 3 } val filteredList = list.filter { str -> str != "bb" } // filteredList = { "a", "ccc" }