Motoi Washida
August 22, 2017
1.1k

# apply() 要らなくない?

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

August 22, 2017

## Transcript

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

3PPN\$MJQהְֲ؎ٝذٔ،ⱖ溪ך \$(.׾Ꟛ涪⚥

7. None

10. None

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) })

19. None

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, 4) Λग़ྗͦ͠͏
23. ### ⢽ 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) Λग़ྗ (※)

26. ### ➿剏周 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) Λग़ྗ
27. ### ➿剏周 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) Λग़ྗ

29. ### ➿剏周 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) Λग़ྗ
30. ### ➿剏周 せ⵸➰ֹ䒷侧 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) Λग़ྗ

37. None