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. ࣗѐ • KAKAOPAY উ٘۽੉٘ ౱ • ੹) ਃӝਃ উ٘۽੉٘ ౱

    • Է ݆਷ ѐߊ੗о غ੗! ࠶۽Ӓ ਍৔ • GDG Seoul/Kotlin korea(ಕ੉झ ࠘ ਍৔૓)/٘۽੉٘ա੉எ ਍৔૓
  2. kotlin • JetBrainsীࢲ 2011֙ ҕѐೠ ೐۽Ӓې߁ ঱য • JVM ӝ߈

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

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

    ৻ Command lineਵ۽ ࠽٘ ജ҃ ҳ୷ оמ • Try Online ࢎ੉౟ীࢲب పझ౟ оמ • https://play.kotlinlang.org
  6. Google਷ ৵ ௏ౣܽਸ? • 2017֙ Google I/Oীࢲ ௏ౣܽਸ উ٘۽੉٘ ѐߊ

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

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

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

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

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

    Kotlinী ೙ਃೠ ۄ੉࠳۞ܻܳ Android KTX۽ ߓನ೧઱Ҋ ੓׮ Android 9(API 28)ࠗఠ ੗߄ ۄ੉࠳۞ܻীࢲ NPE(NullPointerException)ী ؀ೠ ઱ࢳ੉ ನೣغয ѐߊী ଵҊ оמ Kotlin ೟णਸ द੘ೞח ؘ ب਑੉ غח ৈ۞ ഋध੄ ࢠ೒ ௏٘ ઁҕ
  12. ೣࣻ ಴അ ߨ [੽Ӕ੗] fun ೣࣻݺ(߸ٜࣻ: Type): ReturnType { [return]

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

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

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

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

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

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

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

    [੽Ӕ੗] ReturnType ೣࣻݺ(߸ٜࣻ) { [return] } Set fun setName(name: String) { // ... } return fun getName(): String { return "" } fun getName(): String = “" fun getName() = “" Kotlin Java
  20. ఋੑ 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੉ ؀ޙ੗۽ द੘
  21. ߸ࣻ ಴അ Kotlin Java [੽Ӕ੗] var/val <propertyName>[: <PropertyType>] [= <property_initializer>]

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

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

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

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

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

    [<getter>] [<setter>] [੽Ӕ੗] [static final] Type VariableName [= <initializer>] ߸ࣻ ୡӝച ߸ࣻ ୡӝച
  27. ߸ࣻ ಴അ (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";
  28. : 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"
  29. 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
  30. यӖహ ಴അ object Eager public class Eager { private static

    Eager instance = new Eager(); private Eager() {} public Eager getInstance() { return instance; } } Kotlin Java
  31. 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
  32. 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
  33. 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
  34. 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
  35. 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) }
  36. Convert • Java ౵ੌীࢲ Java ޙߨਵ۽ ੘ࢿ • Convert •

    Command + option + Shift + k(ctrl + alt + shift + k) ా • ௏٘ ࠶۾ ઺ ೙ਃೠ ࠗ࠙݅ ࠂࢎ ࠢৈ֍ӝ द Convert
  37. Convert द • Convert റ য়ܨ ௏٘ ࣻ੿ • ޙߨ

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

    ߊࢤೡ ࣻ ੓׮. • ੉ ҃਋ NullPointerException੉ ঱ઁٚ ߊࢤ оמ • Null safe ߑߨਵ۽ ੽Ӕ೧ࢲ NPE ߊࢤਸ ઴ੋ׮. • value?.getXXXX
  39. ѾҴ • Java ࠁ׮ рѾೠ ಴അ • Java੄ ߡ੹җ ޖҙೞѱ

    ୭न ݽ؍ ঱যܳ ഝਊ оמ • ௏ܖ౯ ഝਊਵ۽ Thread ࠁ׮ औѱ ࠺زӝ ୊ܻ оמ • NullPointerExceptionীࢲ ઑӘ੉ա݃ ߩযզ ࣻ ੓ѱ উ੹ೠ null ୊ܻ оמ • ୶റ Kotlin Native੄ ߊ੹ਵ۽ ׮নೠ ೒ۖಬীࢲ ഝਊ оמࢿ