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. ςΩετ 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]
  2. ςΩετ 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
  3. ςΩετ KEYWORD ▸ it ▸ 1 ͭͷҾ਺Λ࣋ͭϒϩοΫͷҾ਺Λ it ͰࢀরͰ͖Δ fun

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

    main(args: Array<String>) { listOf(1, 2, 3) .filter {it < 3} .let {print(it)} }
  5. ςΩετ 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)} }
  6. ςΩετ 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)]