Slide 1

Slide 1 text

௏ౣܽ੉ উ٘۽੉٘ ѐߊী ޷஘ ৔ೱ ӂకജ ஠஠য়ಕ੉

Slide 2

Slide 2 text

• KAKAOPAY উ٘۽੉٘ ౱ • Է ݆਷ ѐߊ੗о غ੗! ࠶۽Ӓ ਍৔ • https://thdev.tech • GDG Seoul ਍৔૓ • ٘۽੉٘ա੉எ ਍৔૓ • [email protected]

Slide 3

Slide 3 text

• Kotlin ঌইࠁӝ • Google Kotlin ૑ਗ • Coroutinesਸ ઑӘ ঌইࠁҊ • Kotlin ૑ਗ ۄ੉࠳۞ܻ ഛੋ • Coroutines ૑ਗ ۄ੉࠳۞ܻ ഛੋ द੘ೞӝ ੹ী

Slide 4

Slide 4 text

੷ח

Slide 5

Slide 5 text

ਃӝਃী Kotlin ੸ਊ ੷ח 2011 2012 2016 2017 2018 v1.1 ٸ ࠗఠ ҕࠗ ਬؘ޷ ъ੄ب ೠߣ ନҊ ড 40% Kotlin ੸ਊ Coroutines ୊਺ ੸ਊ 2019 Kotlin coroutines ݅ ࢎਊ

Slide 6

Slide 6 text

• Java ௏٘۽ ੘ࢿೠ ௏٘ܳ Kotlinਵ۽ ߸ജ • RxJava, MVP ಁఢ ١ਸ ೠߣী ೟ण • ਬؘ޷ ъ੄ܳ ନਵݶࢲ ળ࠺ೠ ੗ܐ۽ ೟ण۱ ૐ؀ • ഥࢎীࢲ पઁ ੸ਊ • Kotlin/coroutines • пઙ ௏ౣܽ ҙ۲ ߊ಴ ೟ण ߑߨ

Slide 7

Slide 7 text

• IO 2017੉ ՘աҊ ഥࢎী جইо ੸ਊೞѷ׮Ҋ ࠁҊ(যו੿ب ೟णೠ Ѧ ঌӝী थੋ) • ࢜۽਍ ചݶী ੸ਊ റ উ੿੸ੋ૑ ࠁҊ, ੉റ ӝઓ ചݶ ߸ജ ࣻ੿ द ୶о ੸ਊ • ಕয೐۽Ӓې߁ਸ ా೧ ೟णബҗ ૐ؀ • Kotlin documents ୭؀ೠ ഝਊ https://kotlinlang.org/docs/reference/ • Kotlin convert ୭؀ೠ ഝਊ җѢ ഥࢎীࢲ ੸ਊ ߑߨ

Slide 8

Slide 8 text

Kotlinਸ ঌইࠁ੗

Slide 9

Slide 9 text

Kotlin? • JetBrains ѐߊ ઱ب • Apache 2 license ӝ߈੄ য়೑ࣗझ • JVMਤীࢲ ز੘ೞח ੿੸ ঱য • Java৬ ࢚ഐ ഐജ оמ(100%) • Coroutines ઁҕ(Asynchronous programming) • Effective Java ܙਸ ই઱ ੜ ૑ఃҊ ੓ח ঱য • Effective Java ଼ ࠁחѤ ୶ୌ

Slide 10

Slide 10 text

Kotlin history 2011 ୭ୡ ҕѐ 2012 Open sourced project Apache 2.0 license 2016 v1.0 release v1.1 release উ੿੸ੋ ঱য۽ ٜযࢲ׮ 2017 Google announced first-class support for Kotlin on Android. v1.2 release 2018 v1.3 release
 v1.0 release coroutines 2019 Kotlin programming language is now its preferred language for Android app developers.

Slide 11

Slide 11 text

Kotlin ஹ౵ੌ

Slide 12

Slide 12 text

Kotlin ӝࠄ ޙߨ

Slide 13

Slide 13 text

var vs val

Slide 14

Slide 14 text

var vs val class Sample { var name: String? = "taehwan" val age: Int = 0 @Test fun test() { println("name $name name.length ${name?.length} age $age") } }

Slide 15

Slide 15 text

var public :nal class Sample { @Nullable private String name = "taehwan"; private :nal int age; @Nullable public :nal String getName() { return this.name; } public :nal void setName(@Nullable String var1) { this.name = var1; } public :nal int getAge() { return this.age; } } var ߸ࣻ name var ߸ࣻ getName() var ߸ࣻ setName()

Slide 16

Slide 16 text

val public :nal class Sample { @Nullable private String name = "taehwan"; private :nal int age; @Nullable public :nal String getName() { return this.name; } public :nal void setName(@Nullable String var1) { this.name = var1; } public :nal int getAge() { return this.age; } } val ߸ࣻ age val ߸ࣻ getAge()

Slide 17

Slide 17 text

Null Safety

Slide 18

Slide 18 text

Null Safety class Sample { var name: String? = "taehwan" @Test fun test() { println("name $name name.length ${name?.length}") } } ? ࠢৈ null ೲਊ nullਸ ࢎਊೞӝ ਤ೧ࢲ ? ୊ܻ

Slide 19

Slide 19 text

Null Safety public :nal class Sample { @Nullable private String name = "taehwan"; @Nullable public :nal String getName() { return this.name; } public :nal void setName(@Nullable String var1) { this.name = var1; } @Test public :nal void test() { StringBuilder var10000 = (new StringBuilder()).append("name ").append(this.name).append(" name.length "); String var10001 = this.name; String var1 = var10000.append(var10001 != null ? var10001.length() : null).toString(); System.out.println(var1); } } @Nullable чਸ ೲਊ 3೦धਵ۽ ߸ജ

Slide 20

Slide 20 text

NonNull or NotNull

Slide 21

Slide 21 text

NotNull class Sample { var name: String = "taehwan" @Test fun test() { println("name $name name.length ${name.length}") } } ?о হয NotNull NotNull਷ Ӓր ࢎਊ

Slide 22

Slide 22 text

NotNull public :nal class Sample { @NotNull private String name = "taehwan"; @NotNull public :nal String getName() { return this.name; } public :nal void setName(@NotNull String var1) { Intrinsics.checkParameterIsNotNull(var1, ""); this.name = var1; } @Test public :nal void test() { String var1 = "name " + this.name + " name.length " + this.name.length(); System.out.println(var1); } } NotNull ੉޲۽ null ୓௼ ۽૒

Slide 23

Slide 23 text

String template

Slide 24

Slide 24 text

String template println("name $name name.length ${name.length}") @Test public :nal void test() { String var1 = "name " + this.name + " name.length " + this.name.length(); System.out.println(var1); } ߸ࣻ݅ ॶٸ ߸ࣻ ੉࢚ਸ ॶٸ ੗߄ীࢲח +۽ ೤஘׮

Slide 25

Slide 25 text

Class ࢚ࣘ

Slide 26

Slide 26 text

Class ࢚ࣘ class Test public :nal class Test { } Kotlin class ੿੄ Javaীࢲח final੉ ನೣ

Slide 27

Slide 27 text

Class ࢚ࣘ - open open class Test public class Test { } Open keyword Final੉ হ׮

Slide 28

Slide 28 text

abstract class abstract class Test public abstract class Test { } Kotlin class ੿੄ Javaীࢲח final੉ ನೣ

Slide 29

Slide 29 text

Etc

Slide 30

Slide 30 text

Data class • data class(equals, hash, toString() ١ ઁҕ) • data class DataClass(val name: String)

Slide 31

Slide 31 text

Infix notation inline infix fun Int.sum(b: Int) = this + b 10 sum 10

Slide 32

Slide 32 text

Higher-Order function val sum: Int.(b: Int) -> Int = { this + b } println(10.sum(10))

Slide 33

Slide 33 text

Stream val list = mutableListOf(1, "a", 10.0f, 22.00, sum) list .asSequence() .filter { it is Int } .map { it as Int } .forEach { println(it.sum(it)) }

Slide 34

Slide 34 text

Google kotlin ૑ਗ

Slide 35

Slide 35 text

2017 Google I/O Android ѐߊ ݫੋ ঱য ૑ਗ ഛ؀۽ Kotlin ঱য ࢶఖ

Slide 36

Slide 36 text

Jetpack - KTX Library • KTX ۄ੉࠳۞ܻܳ ࣗѐ (https://developer.android.com/kotlin/ktx) • Extension functions • Extension properties • Lambdas • Named parameters • Parameter default values // Commit a new value asynchronously sharedPreferences.edit { putBoolean("key", value) }

Slide 37

Slide 37 text

Google I/O 2019

Slide 38

Slide 38 text

Kotlin First

Slide 39

Slide 39 text

• Architecture Components ࣁ࣌ীࢲ coroutines ૑ਗਸ ঌܿ Coroutines Support hnps://www.youtube.com/watch?v=Qxj2eBmXLHg

Slide 40

Slide 40 text

Kotlin First and coroutines support • Google I/O App - 2018 Kotlin base • Sunflowerer example • Codelab • Sample code hnps://developer.android.com/kotlin/resources

Slide 41

Slide 41 text

Additional Kotlin resources hnps://developer.android.com/kotlin/resources

Slide 42

Slide 42 text

Google I/O 2019 • Kotlin਷ о੢ ࡅܰѱ ߊ੹ೞח ঱য ઺ ೞա • Androidীࢲ 50%੄ ѐߊ੗о Kotlin ࢎਊ • Jetpack Architecture Componentsী coroutines ੸ਊ • APIs ٣੗ੋ਷ Kotlin ਤ઱۽ ઁҕ(Kotlin nullability annotation ੸ਊ) • Jetpack KTX ੉৻ীب ੸ӓ੸ਵ۽ Kotlin بੑ ৘੿ • KTX https://developer.android.com/kotlin/ktx.html • Benchmark https://developer.android.com/studio/profile/benchmark.html

Slide 43

Slide 43 text

Coroutinesਸ ઑӘ ঌইࠁҊ о੗

Slide 44

Slide 44 text

• CoroutineScope / GlobalScope • Coroutineਸ ز੘ೞӝ ਤೠ ࢤࢿ੗ • Coroutines प೯ਸ ਤೠ blocks • launch, async/await ١ਸ ઁҕ • ௏ܖ౯ਸ ز੘ दఃӝ ਤೠ blocks • Dispatchers • Main(UI ୊ܻ), IO(ߔӒۄ਍٘ ੘স) झாે۞ܳ ઁҕ • suspend • ೣࣻ۽ coroutinesਸ ੿੄ Coroutinesਸ ઑӘ ঌইࠁҊ о੗

Slide 45

Slide 45 text

Coroutines @Test fun coroutinesTest() { CoroutineScope(Dispatchers.Default).launch { delay(500L) println("ࠗ࢑") } print("Hello, GDG ") Thread.sleep(1000L) }

Slide 46

Slide 46 text

• Coroutines for asynchronous programming and more • https://kotlinlang.org/docs/reference/coroutines-overview.html Coroutinesਸ ઑӘ ঌইࠁҊ о੗

Slide 47

Slide 47 text

Kotlinਵ۽ ߸ജ ઺ੋ ۄ੉࠳۞ܻ

Slide 48

Slide 48 text

• OkHttp੄ Kotlin ߸ജ ੘স • Java 59.1% • Kotlin 40.8% • Kotlin/Coroutines ۄ੉࠳۞ܻ ੄ઓࢿ ೙ਃ • minSdk 21 OkHttp hnps://github.com/square/okhnp/issues/4723

Slide 49

Slide 49 text

• RxJava৬ ೣԋ ࢎਊ • Android UI੄ ׮নೠ ੉߮౟ܳ RxJava ߄ੋ٬(Observable) • RxBinding 3.x ӝળ • Java 45.6% • Kotlin 54.1% RxBinding hnps://github.com/JakeWhason/RxBinding

Slide 50

Slide 50 text

Kotlin ੹ਊ ۄ੉࠳۞ܻ

Slide 51

Slide 51 text

• RxKotlin਷ RxJava ؀୓ਊ੉ ইצ ഛ੢ਸ ૑ਗ • ৮੹ೠ RxKotlin਷ ই૒ ઓ੤ೞ૑ ঋ਺ RxKotlin hnps://github.com/ReactiveX/RxKotlin fun main(args: Array) { val list = listOf("Alpha", "Beta", "Gamma", "Delta", "Epsilon") list.toObservable() // extension function for Iterables .filter { it.length >= 5 } .subscribeBy( // named arguments for lambda Subscribers onNext = { println(it) }, onError = { it.printStackTrace() }, onComplete = { println("Done!") } ) }

Slide 52

Slide 52 text

• Kotlin ੹ਊ DI(dependency injection) • A pragmatic lightweight dependency injection framework for Kotlin developers. • Koin is a DSL, a light container and a pragmatic API KOIN hnps://github.com/InsesKoinIO/koin

Slide 53

Slide 53 text

Coroutines ૑ਗ ࠗ࠙

Slide 54

Slide 54 text

• Type-safe HTTP client for Android and Java by Square, Inc. • Coroutines ૑ਗ • Jake Wharton੉ ٜ݅঻؍ Adapterח ؊ ੉࢚ ߓನೞ૑ ঋח׮. Retrofit hnps://github.com/square/retrout @GET("api/me") suspend fun getUser(@Query(“id”) id: Long): Response

Slide 55

Slide 55 text

• ViewModelScope : androidx.lifecycle:lifecycle-viewmodel-ktx:2.1.0-beta01 • LifecycleScope : androidx.lifecycle:lifecycle-runtime-ktx:2.2.0-alpha01 • liveData : androidx.lifecycle:lifecycle-livedata-ktx:2.2.0-alpha01 Use Kotlin coroutines with Architecture components hnps://developer.android.com/topic/libraries/architecture/coroutines

Slide 56

Slide 56 text

class MyViewModel: ViewModel() { init { viewModelScope.launch { // Coroutine that will be canceled when the ViewModel is cleared. } } } ViewModelScope hnps://developer.android.com/topic/libraries/architecture/coroutines

Slide 57

Slide 57 text

class MyFragment: Fragment() { override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) viewLifecycleOwner.lifecycleScope.launch { val params = TextViewCompat.getTextMetricsParams(textView) val precomputedText = withContext(Dispatchers.Default) { PrecomputedTextCompat.create(longTextContent, params) } TextViewCompat.setPrecomputedText(textView, precomputedText) } } } LifecycleScope hnps://developer.android.com/topic/libraries/architecture/coroutines

Slide 58

Slide 58 text

val user: LiveData = liveData { val data = database.loadUser() // loadUser is a suspend function. emit(data) } Use coroutines with LiveData hnps://developer.android.com/topic/libraries/architecture/coroutines

Slide 59

Slide 59 text

Feature

Slide 60

Slide 60 text

• Kotlinਸ ݽܰҊ উ٘۽੉٘ ѐߊ਷ য۵׮ • Javaب ই૒਷ ঌইঠ ೠ׮.(ݽٚ ഥࢎীࢲ ই૒ Kotlinਸ ॳחѤ ইפ׮) • Kotlin + coroutines਷ ঌইفݶ જ׮. • Flutterب ঌইفݶ… Feature

Slide 61

Slide 61 text

End…