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

    View full-size slide

  2. ςΩετ
    KOTLIN
    ▸ JetBrains ͕։ൃͨ͠ JVM Ͱಈ͘ݴޠ
    ▸ Ϟμϯͳจ๏ΛऔΓೖΕͨ Better Java ͳݴޠ
    ▸ 1.0.0 ͕͍ͭ࠷ۙϦϦʔε͞Εͨ

    View full-size slide

  3. ςΩετ
    MODERN SYNTAX IN KOTLIN
    ▸ Ϧετͷૢ࡞
    ▸ filter, map, let ͳͲศརͳϝιου͕͋Δ
    ▸ Java8 ͷ Stream API Έ͍ͨͳ΋ͷ͕ඪ४౥ࡌ
    fun main(args: Array) {
    listOf(1, 2, 3)
    .filter {n -> n < 3}
    .let {n -> print(n)}
    }
    => [1, 2]

    View full-size slide

  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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

  9. ςΩετ
    data class Article
    (val name: String, val shared: Boolean);
    fun main(args: Array) {
    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)]

    View full-size slide