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

apply() 要らなくない?

apply() 要らなくない?

2017年の夏のKotlin LT祭での発表資料です。
https://kotlin.connpass.com/event/61427/

6afc0de9d281c1ebf568f4e0fe1ddc0b?s=128

Motoi Washida

August 22, 2017
Tweet

Transcript

  1. BQQMZ 銲׵זֻזְ 똲歊㛇

  2. 荈䊹稱➜

  3. 荈䊹稱➜ ˖ せ⵸똲歊㛇 ˖ 5XJUUFS!XN ˖ "OESPJEؒٝآص، J04瘝׮װ׷  ˖

    3PPN$MJQהְֲ؎ٝذٔ،ⱖ溪ך $(.׾Ꟛ涪⚥
  4. (PPHMF*0ך傈ח,PUMJO䱰欽׃ת׃׋

  5. ֿ׸ַ׵
 ,PUMJO娖♲٠剢ך
 蕯鰳罏ָז׿ַ鎉ְתׅ

  6. ➙傈鎉ְ׋ְ✲

  7. None
  8. BQQMZ

  9. 銲׵זֻזְ

  10. None
  11. BQQMZ

  12. أ؝٦فꟼ侧ך♧א ⴱ劍⻉ָٖؒؖٝز ח剅ֽ׷

  13. BQQMZ ⢪׻זְה // { "key1": 1, "key2": 8 } //

    ΛҾ਺ʹͯؔ͠਺Λݺͼ͍ͨ val map = Bundle() map.putInt("key1", 1) map.putInt("key2", 8) someFunction(map)
  14. BQQMZ ⢪ֲה // { "key1": 1, "key2": 8 } //

    ΛҾ਺ʹͯؔ͠਺Λݺͼ͍ͨ someMethod(Bundle().apply { putInt("key1", 1) putInt("key2", 8) })
  15. 瀉ְ

  16. ֶ׃ׯ׸

  17. ,PUMJOז׵דכ ˟ הְֲ״׶+BWB 4XJGU鴟׶חכזְ

  18. ד׮✉欽ׅ׷ה 汤ְ湡鋅׉ֲ

  19. None
  20. ㄎן⳿׃㼎韋ָ ♶僇然ח

  21. ⢽ class Point { var x = 0; var y

    = 0 } var y = 0 // ม਺એݴ val p = Point().apply { x = 3 y = 4 // Ͳͬͪͷ y? } println("p = (${p.x}, ${p.y})") // p = (3, 4) Λग़ྗͦ͠͏
  22. ⢽ class Point { var x = 0; var y

    = 0 } var y = 0 // ม਺એݴ val p = Point().apply { x = 3 y = 4 // Ͳͬͪͷ y? } println("p = (${p.x}, ${p.y})") // p = (3, 0) Λग़ྗ (※)
  23. ➿剏周

  24. BMTP

  25. ➿剏周 class Point { var x = 0; var y

    = 0 } var y = 0 val p = Point().apply { x = 3 y = 4 } println("p = (${p.x}, ${p.y})") // p = (3, 0) Λग़ྗ
  26. ➿剏周 BMTP class Point { var x = 0; var

    y = 0 } var y = 0 val p = Point().also { it.x = 3 it.y = 4 } println("p = (${p.x}, ${p.y})") // p = (3, 4) Λग़ྗ
  27. せ⵸➰ֹ䒷侧

  28. ➿剏周 class Point { var x = 0; var y

    = 0 } var y = 0 val p = Point().apply { x = 3 y = 4 } println("p = (${p.x}, ${p.y})") // p = (3, 0) Λग़ྗ
  29. ➿剏周 せ⵸➰ֹ䒷侧 class Point(val x: Int, val y: Int) var

    y = 0 val p = Point( x = 3, y = 4 ) println("p = (${p.x}, ${p.y})") // p = (3, 4) Λग़ྗ
  30. 猘鋅

  31. BQQMZ ״׶BMTP 
 ך倯ָ㸜Ⰻ

  32. ➙儗ךⶰ⡲欽ָ㼰זְ 鏣鎘أة؎ٕז׵ ⢪ֲ堣⠓ָקרזְ

  33. את׶

  34. BQQMZ SVO XJUIכ MFU BMTPד➿欽

  35. דְְךדכ

  36. None
  37. ׀䠐鋅⹫꧊⚥

  38. ΤϯδχΞืूத ͓ؾܰʹ࿈བྷ͍ͩ͘͞ʂ