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

Korea Community Day 2019

TaeHwan
February 23, 2019

Korea Community Day 2019

KCD 2019 Kotlin init.

TaeHwan

February 23, 2019
Tweet

More Decks by TaeHwan

Other Decks in Education

Transcript

  1. ҳӖ੉ ࢶఖೠ ௏ౣܽ? ৵ જਸө?
    Taehwan

    [email protected]

    View full-size slide

  2. ࣗѐ
    • KAKAOPAY উ٘۽੉٘ ౱

    • ੹) ਃӝਃ উ٘۽੉٘ ౱

    • Է ݆਷ ѐߊ੗о غ੗! ࠶۽Ӓ ਍৔

    • GDG Seoul/Kotlin korea(ಕ੉झ
    ࠘ ਍৔૓)/٘۽੉٘ա੉எ ਍৔૓

    View full-size slide

  3. kotlin
    • JetBrainsীࢲ 2011֙ ҕѐೠ ೐۽Ӓې߁ ঱য

    • JVM ӝ߈ ঱য੉ݴ, Java৬ ࢚ഐ ഐജ 100% ૑ਗ

    • ੗߄ ࠁ׮ উ੹ೠ null ୊ܻܳ ૑ਗೠ׮

    • ഛ੢ ೣࣻ, ো࢑੗ য়ߡ ۽٬ਸ ૑ਗೠ׮

    • DSL(domain-specific languages)ਸ ૑ਗೠ׮

    • coroutinesਸ ૑ਗೠ׮

    View full-size slide

  4. kotlin
    • Developer: JetBrains - open source contributors
    • Stable release: Kotlin 1.3.21 / February 6, 2019
    • Filename : .kt

    • First appeared: 2011

    • Rule of Effective Java

    View full-size slide

  5. kotlin native
    • ௏ౣܽਸ ా೧ ׮নೠ ೒ۖಬ੄ ѐߊ੉ оמೞ׮.

    • അ੤ ૑ਗೞח kotlin native

    • iOS (arm32, arm64, emulator x86_64)

    • MacOS (x86_64)

    • Android (arm32, arm64)

    • Windows (mingw x86_64)

    • Linux (x86_64, arm32, MIPS, MIPS little endian)

    • WebAssembly (wasm32)

    View full-size slide

  6. kotlin
    • Jetbrains੄ IntelliJ IDEA, Android Studioীࢲ оמ

    • Ӓ ৻ Command lineਵ۽ ࠽٘ ജ҃ ҳ୷ оמ

    • Try Online ࢎ੉౟ীࢲب పझ౟ оמ

    • https://play.kotlinlang.org

    View full-size slide

  7. Googleীࢲ ଻ఖೠ
    kotlin

    View full-size slide

  8. Google਷ ৵ ௏ౣܽਸ?
    • 2017֙ Google I/Oীࢲ ௏ౣܽਸ উ٘۽੉٘ ѐߊ ঱য۽ ଻ఖ
    ೮਺ਸ ঌ۷׮

    • ׮নೠ ഥࢎীࢲ ௏ౣܽਸ উ੿੸ਵ۽ ࢎਊ

    View full-size slide

  9. উ٘۽੉٘੄ ೠ҅
    • ୭न ੗߄ܳ ૑ਗೞӝ ਤ೧ࢲח

    • উ٘۽੉٘ ೒ۖಬҗ ࢎਊ੗ٜ੄ ജ҃੉ ߸೧ঠ ೠ׮.

    • Java 1.8ਸ ࢎਊೞ۰ݶ ߹ب੄ ߔನ౟ ۄ੉࠳۞ܻܳ ഝਊ

    • ۈ׮ ಴അध, ੌࠗ झ౟ܿ ೣࣻ ࢎਊ ١

    View full-size slide

  10. উ٘۽੉٘ ೠ҅ܳ ೧Ѿ ೞӝ ਤೠ ߑߨ
    • ௏ౣܽਸ ഝਊೞח ߑߨ

    • ࢜۽਍ ঱যܳ ߓਕঠ ೞח ױ੼

    • Java୊ۢ ߡ੹ী ҳগ߉૑ ঋҊ ୭न ঱য ಁ۞׮੐ਸ ೟ण

    • Java৬ 100% ഐജ

    • inline, ۈ׮ ಴അध, झ౟ܿ ١ ߡ੹ী ޖҙೞѱ ࢎਊ оמ

    • ௏ܖ౯੄ ࢎਊ оמ

    • উ٘۽੉٘ ജ҃ী ઁড੉ হ׮.

    • ز੘ೞח ௏٘ח JDK 1.6ਸ ӝળਵ۽ ࠽٘

    View full-size slide

  11. ҳӖҗ য়ۄ௿ ޙઁ?
    • ௏ౣܽਸ ࢎਊೠ׮Ҋ ೧ࢲ JVMਸ ߩযա૑ ঋח׮.

    • ঱ઃо? ই݃ب? Kotlin native۽ Ү୓೧ࠅ ࣻ ੓ਸ૑ب

    View full-size slide

  12. Googleীࢲ ௏ౣܽ ࢲನ౟
    ࣁ۲غҊ ಴അ۱੉ ڪযթ
    উ੹ೠ ௏٘ ഝਊ੉ оמ

    @Nullable, @NonNull੄ ݺदܳ ా೧ Java to kotlin ࢎਊী ب਑੉ ػ׮
    ࢚ഐ ਍ਊ оמ

    Kotlinীࢲח ੗߄ ӝ߈ ௏٘ܳ ੗ਬ܂ѱ ࠛ۞ৢ ࣻ ੓Ҋ,

    Javaীࢲח ௏ౣܽਸ ੗ਬ܂ѱ ࠛ۞ৢ ࣻ ੓׮.

    View full-size slide

  13. Googleীࢲ ௏ౣܽ ࢲನ౟
    Android Studioܳ ా೧ ࠽٘, ߸ജ ١ਸ ઁҕ
    Kotlinী ೙ਃೠ ۄ੉࠳۞ܻܳ Android KTX۽ ߓನ೧઱Ҋ ੓׮
    Android 9(API 28)ࠗఠ ੗߄ ۄ੉࠳۞ܻীࢲ
    NPE(NullPointerException)ী ؀ೠ ઱ࢳ੉ ನೣغয ѐߊী ଵҊ оמ
    Kotlin ೟णਸ द੘ೞח ؘ ب਑੉ غח ৈ۞ ഋध੄ ࢠ೒ ௏٘ ઁҕ

    View full-size slide

  14. ઱ਃ ޙߨ ࠺Ү
    Java vs kotlin

    View full-size slide

  15. ೣࣻ ಴അ ߨ

    View full-size slide

  16. ೣࣻ ಴അ ߨ
    [੽Ӕ੗] fun ೣࣻݺ(߸ٜࣻ: Type): ReturnType {
    [return]
    }
    [੽Ӕ੗] ReturnType ೣࣻݺ(Type ߸ٜࣻ) {
    [return]
    }
    Kotlin
    Java

    View full-size slide

  17. ೣࣻ ಴അ ߨ
    [੽Ӕ੗] fun ೣࣻݺ(߸ٜࣻ: Type): ReturnType {
    [return]
    }
    [੽Ӕ੗] ReturnType ೣࣻݺ(Type ߸ٜࣻ) {
    [return]
    }
    Kotlin
    Java
    public/private/protected private/protected

    View full-size slide

  18. ೣࣻ ಴അ ߨ
    [੽Ӕ੗] fun ೣࣻݺ(߸ٜࣻ: Type): ReturnType {
    [return]
    }
    [੽Ӕ੗] ReturnType ೣࣻݺ(Type ߸ٜࣻ) {
    [return]
    }
    Kotlin
    Java
    Return type Return type

    View full-size slide

  19. ೣࣻ ಴അ ߨ
    [੽Ӕ੗] fun ೣࣻݺ(߸ٜࣻ: Type): ReturnType {
    [return]
    }
    [੽Ӕ੗] ReturnType ೣࣻݺ(Type ߸ٜࣻ) {
    [return]
    }
    Kotlin
    Java
    Function name Function name

    View full-size slide

  20. ೣࣻ ಴അ ߨ
    [੽Ӕ੗] fun ೣࣻݺ(߸ٜࣻ: Type): ReturnType {
    [return]
    }
    [੽Ӕ੗] ReturnType ೣࣻݺ(Type ߸ٜࣻ) {
    [return]
    }
    Kotlin
    Java
    Parameter Name
    Parameter Name

    View full-size slide

  21. ೣࣻ ಴അ ߨ
    [੽Ӕ੗] fun ೣࣻݺ(߸ٜࣻ: Type): ReturnType {
    [return]
    }
    [੽Ӕ੗] ReturnType ೣࣻݺ(Type ߸ٜࣻ) {
    [return]
    }
    Kotlin
    Java
    Parameter Type
    Parameter Type

    View full-size slide

  22. ೣࣻ ಴അ ߨ
    [੽Ӕ੗] fun ೣࣻݺ(߸ٜࣻ: Type): ReturnType {
    [return]
    }
    [੽Ӕ੗] ReturnType ೣࣻݺ(Type ߸ٜࣻ) {
    [return]
    }
    Kotlin
    Java
    Function block Function block

    View full-size slide

  23. ೣࣻ ಴അ ߨ
    [੽Ӕ੗] fun ೣࣻݺ(߸ٜࣻ): ReturnType {
    [return]
    }
    [੽Ӕ੗] ReturnType ೣࣻݺ(߸ٜࣻ) {
    [return]
    }
    Set
    fun setName(name: String) {
    // ...
    }
    return
    fun getName(): String {
    return ""
    }
    fun getName(): String = “"
    fun getName() = “"
    Kotlin
    Java

    View full-size slide

  24. ఋੑ
    Double 64 : 123.5
    Float 32 : 123.5F/
    123.5f
    Long 64 : 123L
    Int 32 : 123
    Short 16
    Byte 8
    String
    Kotlin
    Java
    double 64 : 123.5
    float 32 : 123.5F/
    123.5f
    long 64 : 123L
    int 32 : 123
    short 16
    byte 8
    String
    ೠо૑ ׮ܲ ੼਷ ݽٚ Primitive Types੉ ؀ޙ੗۽ द੘

    View full-size slide

  25. ߸ࣻ ಴അ
    Kotlin
    Java
    [੽Ӕ੗] var/val [: ] [= ]
    []
    []
    -> []ܳ ࢎਊೞח ࠗ࠙਷ ݽف ࢤۚ੉ оמ
    [੽Ӕ੗] [static final] Type VariableName [= ]
    -> []ܳ ࢎਊೞח ࠗ࠙਷ ݽف ࢤۚ੉ оמ

    View full-size slide

  26. ߸ࣻ ಴അ
    Kotlin
    Java
    [੽Ӕ੗] var/val [: ] [= ]
    []
    []
    [੽Ӕ੗] [static final] Type VariableName [= ]
    public/private/protected
    private/protected

    View full-size slide

  27. ߸ࣻ ಴അ
    Kotlin
    Java
    [੽Ӕ੗] var/val [: ] [= ]
    []
    []
    [੽Ӕ੗] [static final] Type VariableName [= ]
    ߸ࣻ ੿੄

    View full-size slide

  28. ߸ࣻ ಴അ
    Kotlin
    Java
    [੽Ӕ੗] var/val [: ] [= ]
    []
    []
    [੽Ӕ੗] [static final] Type VariableName [= ]
    ߸ࣻ ੉ܴ
    ߸ࣻ ੉ܴ

    View full-size slide

  29. ߸ࣻ ಴അ
    Kotlin
    Java
    [੽Ӕ੗] var/val [: ] [= ]
    []
    []
    [੽Ӕ੗] [static final] Type VariableName [= ]
    ߸ࣻ type
    ߸ࣻ type

    View full-size slide

  30. ߸ࣻ ಴അ
    Kotlin
    Java
    [੽Ӕ੗] var/val [: ] [= ]
    []
    []
    [੽Ӕ੗] [static final] Type VariableName [= ]
    ߸ࣻ ୡӝച
    ߸ࣻ ୡӝച

    View full-size slide

  31. ߸ࣻ ಴അ
    (mutable) Read/Write : var
    var variable: String = "a"
    (inmutable) Read only : val
    val variable: String = "a"
    Kotlin
    Java
    (mutable) Read/Write
    String variable = "a";
    (inmutable) Read only : fianl
    final String variable = "a";

    View full-size slide

  32. : String?
    օ୊ܻ
    kotlin਷ nullਸ ೲਊೞ۰ݶ ޛ਺಴(?)
    ݺद۽ nullਸ ࢎਊೡ ࣻ ੓׮.
    var variable
    variable = null
    Kotlin
    Java
    Javaীࢲח ঱ઁٚ nullਸ ೲਊೡ ࣻ ੓
    ׮
    String variable = "a";
    variable = null;
    Null can not be a value of a non-null type String
    = "a"

    View full-size slide

  33. Class ಴അ ߨ
    class KotlinSample constructor(val a:
    String) {
    }
    public class JavaSample {
    private final String a;
    public JavaSample(String a) {
    this.a = a;
    }
    }
    Kotlin਷ class ੉ܴਸ ॹҗ زदী ࢤࢿ੗ܳ ੿੄
    Kotlin
    Java

    View full-size slide

  34. यӖహ ಴അ
    object Eager
    public class Eager {
    private static Eager instance
    = new Eager();
    private Eager() {}
    public Eager getInstance() {
    return instance;
    }
    }
    Kotlin
    Java

    View full-size slide

  35. Higher-Order Functions
    - ೣࣻܳ ౵ۄݫఠ۽ ੹׳, ೣࣻ return
    - lambdaܳ ੉ਊೞৈ ୷ড ഋక۽ ઁҕ
    - ߸ࣻ۽ ೣࣻܳ о૕ ࣻ ੓׮
    fun higherOrder(body: (Int, Int) -> Int) = body(20, 10)
    fun sum(a: Int, b: Int) = a + b
    fun minus(a: Int, b: Int) = a - b
    fun multiply(a: Int, b: Int) = a * b
    fun division(a: Int, b: Int) = a / b
    @Test
    fun test() {
    println(higherOrder(::sum)) // 30
    println(higherOrder(::minus)) // 10
    println(higherOrder(::multiply)) // 200
    println(higherOrder(::division)) // 2
    }
    Kotlin

    View full-size slide

  36. 3 ೦ध
    val l: Int = if (b != null)
    b.length else -1
    Elvis Operator
    val l = b?.length ?: -1
    int length = name != null ?
    name.length() : 0;
    Kotlin਷ 3 ೦ध੉ ઓ੤ೞ૑ ঋইਃ
    Kotlin
    Java

    View full-size slide

  37. Infix notation
    infix fun Int.max(x: Int): Int =
    if (this > x) this else x
    1.max(15)
    public int max(int a, int b) {
    return a > b ? a : b;
    }
    max(1, 2);
    1 max 15
    infix ఃਕ٘ܳ ా೧ 1 max 15 ഋక۽ ಴അ оמ

    ױ, ߸ࣻо 2ѐੋ ҃਋ী݅ оמ
    Kotlin
    Java

    View full-size slide

  38. String templates ੉ਊೞӝ
    val name = "kotlin"
    val age = 10
    val query = "Name: $name Age: $age"
    print : `Name: kotlin Age: 10`
    String name = "kotlin";
    int age = 10;
    String query = "Name: " + name + "
    Age: " + age;
    print : "Name: kotlin Age: 10"
    ௏ౣܽীࢲח + ؀न ${߸ࣻݺ.߸ࣻ} ഋక۽ String ઑ೤੉ оמೞ׮
    Kotlin
    Java

    View full-size slide

  39. Loop
    val arrayList = ArrayList()
    for (item in arrayList) {
    println("List item : $item")
    }
    ArrayList arrayList = new
    ArrayList<>();
    for (String s : arrayList) {
    System.out.println("List item : " +
    s);
    }
    Kotlin
    Java
    for (int i = 1; i <= 5; i++) {
    System.out.println("index : " + i);
    }
    for (x in 1..5) {
    println(x)
    }

    View full-size slide

  40. ௏ౣܽ ೟णߨ

    View full-size slide

  41. ௏ౣܽ ೟णߨ
    • ޙࢲܳ ࠁݶࢲ ೟णೞӝ https://kotlinlang.org/docs/reference/

    View full-size slide

  42. ௏ౣܽ ೟णߨ
    • ௏٘ োण਷ playgroundীࢲ оמ https://play.kotlinlang.org

    View full-size slide

  43. ௏ౣܽ ೟णߨ
    • Kotlin In action

    View full-size slide

  44. ௏ౣܽ ೟णߨ
    • Effective Java in Kotlin : https://blog.kotlin-academy.com/effective-java-in-kotlin-
    item-1-consider-static-factory-methods-instead-of-constructors-8d0d7b5814b2

    View full-size slide

  45. Convert
    • Java ౵ੌীࢲ Java ޙߨਵ۽ ੘ࢿ

    • Convert

    • Command + option + Shift + k(ctrl + alt + shift + k) ా

    • ௏٘ ࠶۾ ઺ ೙ਃೠ ࠗ࠙݅ ࠂࢎ ࠢৈ֍ӝ द Convert

    View full-size slide

  46. Android Studio > Code >
    Convert Java File to Kotlin File

    View full-size slide

  47. Convert द
    • Convert റ য়ܨ ௏٘ ࣻ੿

    • ޙߨ ࢚ য়ܨо ݆ਸ ࣻ ੓ਵפ ରӔରӔ ӝࠄ ޙߨਸ ӝળਵ۽ ౣ
    ܽ Ҕਸ ࣻ੿

    • যו ੿ب ೟ण ബҗо աఋաݶ ௏٘ ઴੉ӝ

    View full-size slide

  48. Java/Kotlin ഝਊद ઱੄
    • @Nullable/@NonNullী ઱੄ೞ੗!

    • Javaীࢲח ঱ઁٚ null੉ ߊࢤೡ ࣻ ੓׮.

    • ੉ ҃਋ NullPointerException੉ ঱ઁٚ ߊࢤ оמ

    • Null safe ߑߨਵ۽ ੽Ӕ೧ࢲ NPE ߊࢤਸ ઴ੋ׮.

    • value?.getXXXX

    View full-size slide

  49. Coroutines
    • Coroutines for asynchronous programming and more

    • https://kotlinlang.org/docs/reference/coroutines-overview.html

    View full-size slide

  50. ѾҴ
    • Java ࠁ׮ рѾೠ ಴അ

    • Java੄ ߡ੹җ ޖҙೞѱ ୭न ݽ؍ ঱যܳ ഝਊ оמ

    • ௏ܖ౯ ഝਊਵ۽ Thread ࠁ׮ औѱ ࠺زӝ ୊ܻ оמ

    • NullPointerExceptionীࢲ ઑӘ੉ա݃ ߩযզ ࣻ ੓ѱ উ੹ೠ null ୊ܻ оמ

    • ୶റ Kotlin Native੄ ߊ੹ਵ۽ ׮নೠ ೒ۖಬীࢲ ഝਊ оמࢿ

    View full-size slide

  51. хࢎ೤פ׮.
    Taehwan

    [email protected]
    2019 ஠஠য়ಕ੉ ҃۱ ҕ଻ ઺

    View full-size slide