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

"It shared" in Kotlin

"It shared" in Kotlin

Keishin Yokomaku

April 15, 2016
Tweet

More Decks by Keishin Yokomaku

Other Decks in Technology

Transcript

  1. IT SHARED IN KOTLIN KEISHIN YOKOMAKU

  2. ςΩετ KOTLIN ▸ JetBrains ͕։ൃͨ͠ JVM Ͱಈ͘ݴޠ ▸ Ϟμϯͳจ๏ΛऔΓೖΕͨ Better

    Java ͳݴޠ ▸ 1.0.0 ͕͍ͭ࠷ۙϦϦʔε͞Εͨ
  3. ςΩετ MODERN SYNTAX IN KOTLIN ▸ Ϧετͷૢ࡞ ▸ filter, map,

    let ͳͲศརͳϝιου͕͋Δ ▸ Java8 ͷ Stream API Έ͍ͨͳ΋ͷ͕ඪ४౥ࡌ fun main(args: Array<String>) { listOf(1, 2, 3) .filter {n -> n < 3} .let {n -> print(n)} } => [1, 2]
  4. ςΩετ MODERN SYNTAX IN KOTLIN ▸ σʔλΫϥε ▸ ϓϩύςΟΛอ࣋͢ΔΫϥε(=Entity)༻ͷಛผͳએݴ ▸

    Getter/Setter ΍ equals/hashCodeɺtoString ΛΑ͠ͳʹ ΍ͬͯ͘ΕΔͷͰࣗ෼Ͱॻ͔ͳ͍͍ͯ͘ data class Person(val name: String, val age: Int) val eq = Person(“Hirata”, 29) .equals(Person(“Jita”, 30)) print(eq) => false
  5. ςΩετ KEYWORD ▸ it ▸ 1 ͭͷҾ਺Λ࣋ͭϒϩοΫͷҾ਺Λ it ͰࢀরͰ͖Δ fun

    main(args: Array<String>) { listOf(1, 2, 3) .filter {n -> n < 3} .let {n -> print(n)} }
  6. ςΩετ KEYWORD ▸ it ▸ 1 ͭͷҾ਺Λ࣋ͭϒϩοΫͷҾ਺Λ it ͰࢀরͰ͖Δ fun

    main(args: Array<String>) { listOf(1, 2, 3) .filter {it < 3} .let {print(it)} }
  7. ςΩετ data class Article (val name: String, val shared: Boolean);

  8. ςΩετ data class Article (val name: String, val shared: Boolean);

    fun main(args: Array<String>) { listOf(Article(“Think Social?”, true), Article(“Facebook”, true), Article(“mixi”, false)) .filter {it.shared} .let {print(it)} }
  9. ςΩετ data class Article (val name: String, val shared: Boolean);

    fun main(args: Array<String>) { listOf(Article(“Think Social?”, true), Article(“Facebook”, true), Article(“mixi”, false)) .filter {it.shared} .let {print(it)} } => [Article(name=“Think Social?”, shared=true), Article(name=“Facebook”, shared=true)]
  10. IT SHARED