Korea Community Day 2019

7589a5a8fec022e8af4e46525150a291?s=47 TaeHwan
February 23, 2019

Korea Community Day 2019

KCD 2019 Kotlin init.

7589a5a8fec022e8af4e46525150a291?s=128

TaeHwan

February 23, 2019
Tweet

Transcript

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

  2. ࣗѐ • KAKAOPAY উ٘۽੉٘ ౱ • ੹) ਃӝਃ উ٘۽੉٘ ౱

    • Է ݆਷ ѐߊ੗о غ੗! ࠶۽Ӓ ਍৔ • GDG Seoul/Kotlin korea(ಕ੉झ ࠘ ਍৔૓)/٘۽੉٘ա੉எ ਍৔૓
  3. kotlin

  4. kotlin • JetBrainsীࢲ 2011֙ ҕѐೠ ೐۽Ӓې߁ ঱য • JVM ӝ߈

    ঱য੉ݴ, Java৬ ࢚ഐ ഐജ 100% ૑ਗ • ੗߄ ࠁ׮ উ੹ೠ null ୊ܻܳ ૑ਗೠ׮ • ഛ੢ ೣࣻ, ো࢑੗ য়ߡ ۽٬ਸ ૑ਗೠ׮ • DSL(domain-specific languages)ਸ ૑ਗೠ׮ • coroutinesਸ ૑ਗೠ׮
  5. kotlin • Developer: JetBrains - open source contributors • Stable

    release: Kotlin 1.3.21 / February 6, 2019 • Filename : .kt • First appeared: 2011 • Rule of Effective Java
  6. 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)
  7. kotlin • Jetbrains੄ IntelliJ IDEA, Android Studioীࢲ оמ • Ӓ

    ৻ Command lineਵ۽ ࠽٘ ജ҃ ҳ୷ оמ • Try Online ࢎ੉౟ীࢲب పझ౟ оמ • https://play.kotlinlang.org
  8. Googleীࢲ ଻ఖೠ kotlin

  9. Google਷ ৵ ௏ౣܽਸ? • 2017֙ Google I/Oীࢲ ௏ౣܽਸ উ٘۽੉٘ ѐߊ

    ঱য۽ ଻ఖ ೮਺ਸ ঌ۷׮ • ׮নೠ ഥࢎীࢲ ௏ౣܽਸ উ੿੸ਵ۽ ࢎਊ
  10. উ٘۽੉٘੄ ೠ҅ • ୭न ੗߄ܳ ૑ਗೞӝ ਤ೧ࢲח • উ٘۽੉٘ ೒ۖಬҗ

    ࢎਊ੗ٜ੄ ജ҃੉ ߸೧ঠ ೠ׮. • Java 1.8ਸ ࢎਊೞ۰ݶ ߹ب੄ ߔನ౟ ۄ੉࠳۞ܻܳ ഝਊ • ۈ׮ ಴അध, ੌࠗ झ౟ܿ ೣࣻ ࢎਊ ١
  11. উ٘۽੉٘ ೠ҅ܳ ೧Ѿ ೞӝ ਤೠ ߑߨ • ௏ౣܽਸ ഝਊೞח ߑߨ

    • ࢜۽਍ ঱যܳ ߓਕঠ ೞח ױ੼ • Java୊ۢ ߡ੹ী ҳগ߉૑ ঋҊ ୭न ঱য ಁ۞׮੐ਸ ೟ण • Java৬ 100% ഐജ • inline, ۈ׮ ಴അध, झ౟ܿ ١ ߡ੹ী ޖҙೞѱ ࢎਊ оמ • ௏ܖ౯੄ ࢎਊ оמ • উ٘۽੉٘ ജ҃ী ઁড੉ হ׮. • ز੘ೞח ௏٘ח JDK 1.6ਸ ӝળਵ۽ ࠽٘
  12. ҳӖҗ য়ۄ௿ ޙઁ? • ௏ౣܽਸ ࢎਊೠ׮Ҋ ೧ࢲ JVMਸ ߩযա૑ ঋח׮.

    • ঱ઃо? ই݃ب? Kotlin native۽ Ү୓೧ࠅ ࣻ ੓ਸ૑ب
  13. Googleীࢲ ௏ౣܽ ࢲನ౟ ࣁ۲غҊ ಴അ۱੉ ڪযթ উ੹ೠ ௏٘ ഝਊ੉ оמ

    @Nullable, @NonNull੄ ݺदܳ ా೧ Java to kotlin ࢎਊী ب਑੉ ػ׮ ࢚ഐ ਍ਊ оמ Kotlinীࢲח ੗߄ ӝ߈ ௏٘ܳ ੗ਬ܂ѱ ࠛ۞ৢ ࣻ ੓Ҋ, Javaীࢲח ௏ౣܽਸ ੗ਬ܂ѱ ࠛ۞ৢ ࣻ ੓׮.
  14. Googleীࢲ ௏ౣܽ ࢲನ౟ Android Studioܳ ా೧ ࠽٘, ߸ജ ١ਸ ઁҕ

    Kotlinী ೙ਃೠ ۄ੉࠳۞ܻܳ Android KTX۽ ߓನ೧઱Ҋ ੓׮ Android 9(API 28)ࠗఠ ੗߄ ۄ੉࠳۞ܻীࢲ NPE(NullPointerException)ী ؀ೠ ઱ࢳ੉ ನೣغয ѐߊী ଵҊ оמ Kotlin ೟णਸ द੘ೞח ؘ ب਑੉ غח ৈ۞ ഋध੄ ࢠ೒ ௏٘ ઁҕ
  15. ઱ਃ ޙߨ ࠺Ү Java vs kotlin

  16. ೣࣻ ಴അ ߨ

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

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

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

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

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

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

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

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

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

  26. ఋੑ 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੉ ؀ޙ੗۽ द੘
  27. ߸ࣻ ಴അ Kotlin Java [੽Ӕ੗] var/val <propertyName>[: <PropertyType>] [= <property_initializer>]

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

    [<getter>] [<setter>] [੽Ӕ੗] [static final] Type VariableName [= <initializer>] public/private/protected private/protected
  29. ߸ࣻ ಴അ Kotlin Java [੽Ӕ੗] var/val <propertyName>[: <PropertyType>] [= <property_initializer>]

    [<getter>] [<setter>] [੽Ӕ੗] [static final] Type VariableName [= <initializer>] ߸ࣻ ੿੄
  30. ߸ࣻ ಴അ Kotlin Java [੽Ӕ੗] var/val <propertyName>[: <PropertyType>] [= <property_initializer>]

    [<getter>] [<setter>] [੽Ӕ੗] [static final] Type VariableName [= <initializer>] ߸ࣻ ੉ܴ ߸ࣻ ੉ܴ
  31. ߸ࣻ ಴അ Kotlin Java [੽Ӕ੗] var/val <propertyName>[: <PropertyType>] [= <property_initializer>]

    [<getter>] [<setter>] [੽Ӕ੗] [static final] Type VariableName [= <initializer>] ߸ࣻ type ߸ࣻ type
  32. ߸ࣻ ಴അ Kotlin Java [੽Ӕ੗] var/val <propertyName>[: <PropertyType>] [= <property_initializer>]

    [<getter>] [<setter>] [੽Ӕ੗] [static final] Type VariableName [= <initializer>] ߸ࣻ ୡӝച ߸ࣻ ୡӝച
  33. ߸ࣻ ಴അ (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";
  34. : 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"
  35. Class

  36. 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
  37. यӖహ ಴അ object Eager public class Eager { private static

    Eager instance = new Eager(); private Eager() {} public Eager getInstance() { return instance; } } Kotlin Java
  38. 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
  39. ӝఋ

  40. 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
  41. 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
  42. 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
  43. Loop val arrayList = ArrayList<String>() for (item in arrayList) {

    println("List item : $item") } ArrayList<String> 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) }
  44. ௏ౣܽ ೟णߨ

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

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

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

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

  49. Convert

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

    Command + option + Shift + k(ctrl + alt + shift + k) ా • ௏٘ ࠶۾ ઺ ೙ਃೠ ࠗ࠙݅ ࠂࢎ ࠢৈ֍ӝ द Convert
  51. Android Studio > Code > Convert Java File to Kotlin

    File
  52. Convert द • Convert റ য়ܨ ௏٘ ࣻ੿ • ޙߨ

    ࢚ য়ܨо ݆ਸ ࣻ ੓ਵפ ରӔରӔ ӝࠄ ޙߨਸ ӝળਵ۽ ౣ ܽ Ҕਸ ࣻ੿ • যו ੿ب ೟ण ബҗо աఋաݶ ௏٘ ઴੉ӝ
  53. Java/Kotlin ഝਊद ઱੄ • @Nullable/@NonNullী ઱੄ೞ੗! • Javaীࢲח ঱ઁٚ null੉

    ߊࢤೡ ࣻ ੓׮. • ੉ ҃਋ NullPointerException੉ ঱ઁٚ ߊࢤ оמ • Null safe ߑߨਵ۽ ੽Ӕ೧ࢲ NPE ߊࢤਸ ઴ੋ׮. • value?.getXXXX
  54. Coroutines

  55. Coroutines • Coroutines for asynchronous programming and more • https://kotlinlang.org/docs/reference/coroutines-overview.html

  56. ѾҴ • Java ࠁ׮ рѾೠ ಴അ • Java੄ ߡ੹җ ޖҙೞѱ

    ୭न ݽ؍ ঱যܳ ഝਊ оמ • ௏ܖ౯ ഝਊਵ۽ Thread ࠁ׮ औѱ ࠺زӝ ୊ܻ оמ • NullPointerExceptionীࢲ ઑӘ੉ա݃ ߩযզ ࣻ ੓ѱ উ੹ೠ null ୊ܻ оמ • ୶റ Kotlin Native੄ ߊ੹ਵ۽ ׮নೠ ೒ۖಬীࢲ ഝਊ оמࢿ
  57. хࢎ೤פ׮. Taehwan taehwan@thdev.net 2019 ஠஠য়ಕ੉ ҃۱ ҕ଻ ઺