Kotlin in Google IO 2017 CA.apk

Kotlin in Google IO 2017 CA.apk

# Event
https://cyberagent.connpass.com/event/55405/

# Links

- 2016年、KotlinでAndroid開発する方へ
- http://qiita.com/satorufujiwara/items/871c5b7b66c7691d82a8

- Google I/O 2017 : Introduction to Kotlin (和訳/要約)
- http://qiita.com/satorufujiwara/items/490c1499acec1a921258

- Life is Great and Everything Will Be Ok Kotlin is Here
- https://speakerdeck.com/jakewharton/life-is-great-and-everything-will-be-ok-kotlin-is-here-google-io-2017
- https://www.youtube.com/watch?v=fPzxfeDJDzY

- Kotlin スコープ関数 用途まとめ@Qiita
- http://qiita.com/ngsw_taro/items/d29e3080d9fc8a38691e

- Kotlin入門までの助走読本
- http://goo.gl/5vUT7o

B0f8177e3259f29952640f98bf795965?s=128

satorufujiwara

May 29, 2017
Tweet

Transcript

  1. Kotlin in Google I/O 2017 2017.05.29 CA.apk #3 @satorufujiwara

  2. About me Satoru Fujiwara (@satorufujiwara) Android Engineer @CyberAgent ,Inc Shibuya.apk

  3. Kotlin & Me FRESH! (KotlinͰ։ൃ 2015೥3݄ʙ) 2016೥ɺKotlinͰAndroid։ൃ͢Δํ΁ @Qiita - goo.gl/0medax

    CA.kt #1 6/15(໦)
  4. Kotlin in Google I/O 2017 @satorufujiwara

  5. Google Keynote

  6. Kotlin in Keynote • KotlinΛAndroidʹ͓͚Δެࣜݴޠͱͯ͠αϙʔτ • JetBrainsࣾΛύʔτʔφʔͱͯ͠Kotlinࡒஂͷઃཱ • طଘͷίʔυ(Java)ʹ΋͞ΒͳΔ౤ࢿΛ͢Δ

  7. Why Kotlin? • Kotlin͸Androidͷ։ൃऀίϛϡχςΟ͕طʹٻΊ͍ͯ ͨݴޠͰɺ։ൃऀͷੜ࢈ੑΛߴΊΔ͜ͱ͕ग़དྷΔ • AndroidͷϥϯλΠϜͱͷ׬શͳޓ׵ੑ͕͋Γɺطଘͷ ίʔυͱͷ૬ޓӡ༻͕ՄೳͰ͋Δ • ૉ੖Β͍͠IDEʹΑΔαϙʔτ

    • ݴޠ͕੒ख़͠ɺ੡඼൛ͱͯ͠ϦϦʔεՄೳͳঢ়ଶͰ͋Δ
  8. Developer Keynote

  9. 4 big themes in Android • Kotlin • Android Studio

    & Libraries • App Quality & Success • Android Instant App
  10. Kotlin in Developer Keynote • First-class Language ʹ • γϯλοΫεϊΠζͷগͳ͍ඒ͍͠ݴޠ

    • Android Studio 3.0 ʹ૊Έࠐ·ΕΔ • Java8 ͷ͞ΒͳΔαϙʔτ(Android O)
  11. Android Studio 3.0

  12. buid.gradle buildscript { ext.kotlin_version = '1.1.2-4' dependencies { classpath 'com.android.tools.build:gradle:3.0.0-alpha1'

    classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" } } app/build.gradle apply plugin: ‘kotlin-android' dependencies { compile "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version" }
  13. Why Kotlin? in Developer Keynote • Kotlin͸Javaͱͷ׬શͳ૬ޓӡ༻͕ग़དྷɺ1Ϋϥε͔ΒKotlinԽͰ͖Δ • 100% interoperable

    with Java and Android • ։ൃ͔Β5೥ܦͪɺݴޠ͕੒ख़͠ɺ੡඼൛ͱͯ͠ϦϦʔεՄೳͳঢ়ଶͰ͋ Γɺ࣮ࡍʹ࢖ΘΕ͍ͯΔ • Flipboard,Pinterest ,Square Cash, Expedia • ݴޠ͕ૉ੖Β͍͠ͷʹՃ͑ɺIDEαϙʔτ͕ૉ੖Β͍͠ • Android Studioͷϕʔεͱͳ͍ͬͯΔIntelliJ IDEAͱಉ͡νʔϜ • Kotlin͸طʹApache2ϥΠηϯεͷΦʔϓϯιʔε͕ͩɺ͜Ε͔Β΋Φʔ ϓϯιʔεϓϩδΣΫτͱͯ͠ඇӦརࡒஂ͕։ൃ͍ͯ͘͠
  14. Sessions about Kotlin • Introduction to Kotlin • Life is

    Great and Everything Will Be Ok, Kotlin is Here
  15. Introduction to Kotlin Google I/O 2017 : Introduction to Kotlin

    (࿨༁/ཁ໿) @Qiita goo.gl/U24xkw
  16. Life is Great and Everything Will Be Ok, Kotlin is

    Here • KotlinͰAndroidΛ։ൃ͢Δ্ͰͷTips • by Jake Wharton (Square) @JakeWharton • KotlinΛ͍͔ʹͯ͠ಋೖ͔ͨ͠ʁ • by Christina Lee (Pinterest) @RunChristinaRun • https://speakerdeck.com/jakewharton/life-is-great-and- everything-will-be-ok-kotlin-is-here-google-io-2017 • https://www.youtube.com/watch?v=fPzxfeDJDzY
  17. Kotlin͕ެࣜݴޠʹͳͬͯ • Android։ൃͰʮKotlinΛબͿ͜ͱʯ͕ग़དྷΔ • Ҿ͖ଓ͖Javaͷ஌ࣝ͸ඞཁ • Swiftͱ͸ࣅͯඇͳΔݴޠɺڞ௨Խ͸ग़དྷͳ͍ • Kotlin͸ࣗ༝౓͕ߴ͘ɺ͜Ε·ͰҎ্ʹֶशɾ νʔϜͰͷٞ࿦͕ඞཁ

  18. Kotlin͸ࣗ༝౓͕ߴ͍

  19. ྫ1: lambda

  20. fun findEmails(users: List<User>, predicate: (String) -> (Boolean)) : List<User> {

    //… } findEmails(users, { value -> value.endsWith(".com") })
  21. fun findEmails(users: List<User>, predicate: (String) -> (Boolean)) : List<User> {

    //… } findEmails(users, { value -> value.endsWith(".com") }) findEmails(users, { it.endsWith(".com") })
  22. fun findEmails(users: List<User>, predicate: (String) -> (Boolean)) : List<User> {

    //… } findEmails(users, { value -> value.endsWith(".com") }) findEmails(users, { it.endsWith(".com") }) findEmails(users) { it.endsWith(".com") }
  23. ྫ2: nullable

  24. data class Money(val amount: Int, val currency: String) fun sumUp(money

    : Money?) { // money is nullable }
  25. data class Money(val amount: Int, val currency: String) fun sumUp(money

    : Money?) { sumOfAmount += money!!.amount }
  26. data class Money(val amount: Int, val currency: String) fun sumUp(money

    : Money?) { sumOfAmount += money!!.amount }
  27. data class Money(val amount: Int, val currency: String) fun sumUp(money

    : Money?) { if (money != null) { sumOfAmount += money.amount } }
  28. data class Money(val amount: Int, val currency: String) fun sumUp(money

    : Money?) { if (money != null) { sumOfAmount += money.amount } } fun sumUp(money : Money?) { money ?: return sumOfAmount += money.amount }
  29. data class Money(val amount: Int, val currency: String) fun sumUp(money

    : Money?) { if (money != null) { sumOfAmount += money.amount } } fun sumUp(money : Money?) { money ?: return sumOfAmount += money.amount } fun sumUp(money : Money?) { sumOfAmount += money?.amount ?: 0 }
  30. data class Money(val amount: Int, val currency: String) fun sumUp(money

    : Money?) { if (money != null) { sumOfAmount += money.amount } } fun sumUp(money : Money?) { money ?: return sumOfAmount += money.amount } fun sumUp(money : Money?) { sumOfAmount += money?.amount ?: 0 } fun sumUp(money : Money?) { money?.run { sumOfAmount += amount } }
  31. ྫ3: είʔϓؔ਺

  32. companion object { private const val KEY_USER = “user” fun

    newInstance(user: User): UserFragment { val fragment = UserFragment() val args = Bundle() args.putParcelable(KEY_USER, user) fragment.argument = args return fragment } }
  33. companion object { private const val KEY_USER = “user” fun

    newInstance(user: User): UserFragment { val fragment = UserFragment() val args = Bundle() args.putParcelable(KEY_USER, user) fragment.argument = args return fragment } fun newInstance(user: User): UserFragment { val fragment = UserFragment() fragment.argument = Bundle().apply { putParcelable(KEY_USER, user) } return fragment } }
  34. companion object { private const val KEY_USER = “user” fun

    newInstance(user: User): UserFragment { val fragment = UserFragment() val args = Bundle() args.putParcelable(KEY_USER, user) fragment.argument = args return fragment } fun newInstance(user: User): UserFragment { val fragment = UserFragment() fragment.argument = Bundle().apply { putParcelable(KEY_USER, user) } return fragment } fun newInstance(user: User) = UserFragment().apply { arguments = Bundle().apply { putParcelable(KEY_USER, user) } } }
  35. είʔϓؔ਺ • let / with / run /apply / also

    • Kotlin είʔϓؔ਺ ༻్·ͱΊ@Qiita • http://qiita.com/ngsw_taro/items/ d29e3080d9fc8a38691e
  36. How to start Kotlin • Official Site : kotl.in/ ,

    kotl.in/android • Kotlin is awesome! (kotlin.link/) • Kotlin ελʔτϒοΫ(੺΂͜ຊ) • Kotlin Advent Calendar (2015/2016)
  37. How to start Kotlin • Official Site : kotl.in/ ,

    kotl.in/android • Kotlin is awesome! (kotlin.link/) • Kotlin ελʔτϒοΫ(੺΂͜ຊ) • Kotlin Advent Calendar (2015/2016) • Kotlinೖ໳·Ͱͷॿ૸ಡຊ( goo.gl/5vUT7o )
  38. Thank you ! Let’s enjoy Kotlin