Slide 1

Slide 1 text

Kotlin 2021 Recap Kenji Abe (@STAR_ZERO) Android, Kotlin GDE / DeNA Co., Ltd. [Tokyo]

Slide 2

Slide 2 text

No content

Slide 3

Slide 3 text

No content

Slide 4

Slide 4 text

Kotlin 1.5

Slide 5

Slide 5 text

value class UserId(val id: Int) val userId = UserId(1)

Slide 6

Slide 6 text

// State.kt sealed interface State // Success.kt data class Success(val data: Data): State // Failure.kt data class Failure(val e: Exception): State

Slide 7

Slide 7 text

val uint: UInt = 1u val ulong: ULong = 2u val ushort: UShort = 3u val ubyte: UByte = 4u

Slide 8

Slide 8 text

val value = "..." value.toUpperCase() value.uppercase() value.toLowerCase() value.lowercase() value.capitalize() value.replaceFirstChar { it.uppercase() } value.decapitalize() value.replaceFirstChar { it.lowercase() }

Slide 9

Slide 9 text

Coroutines 1.5

Slide 10

Slide 10 text

No content

Slide 11

Slide 11 text

val channel = Channel(...) channel.offer("...") // true or false or throw Exception channel.trySend("...") // ChannelResult channel.poll() // get or null channel.tryReceive() // ChannelResult

Slide 12

Slide 12 text

Kotlin Symbol Processing

Slide 13

Slide 13 text

Kotlin Symbol Processing 1. Kotlinの軽量コンパイラプラグイン開発ツール 2. KAPTのような機能 3. KAPTより高速 4. Kotlinのコードを直接解析 5. Multiple Platformのサポート

Slide 14

Slide 14 text

Multiplatform

Slide 15

Slide 15 text

Multiplatform 1. Compose multiplatform 1.0 2. KMM Beta (2022春予定) 3. New Kotlin/Native memory management

Slide 16

Slide 16 text

Kotlin 1.6

Slide 17

Slide 17 text

class Func : suspend (String) -> Result { override suspend fun invoke(s: String): Result { // ... } } val func: suspend (String) -> Result = Func() val result = func("test")

Slide 18

Slide 18 text

annotation class Marker(val value: String) val marker = Marker("Sample")

Slide 19

Slide 19 text

No content

Slide 20

Slide 20 text

// build.gradle kotlin { sourceSets.all { languageSettings { progressiveMode = true } } }

Slide 21

Slide 21 text

No content

Slide 22

Slide 22 text

val sec = 10000.seconds println(sec.inWholeHours) // 2 println(sec.inWholeMinutes) // 166 val duration = sec + 10.hours duration.toComponents { d, h, m, s, ns -> println("${d}d ${h}h ${m}m ${s}s") // => 0d 12h 46m 40s }

Slide 23

Slide 23 text

val list = buildList { add("a") if (condition) { add("b") } add("c") } val map = buildMap { put("a", 1) } val set = buildSet { add("a") }

Slide 24

Slide 24 text

Coroutines 1.6

Slide 25

Slide 25 text

Coroutines 1.6 1. kotlinx-coroutines-test に様々な変更 2. CoroutineDispatcher.limitedParallelism の導入 3. Kotlin/Native new memory model をサポート

Slide 26

Slide 26 text

K2 Compiler

Slide 27

Slide 27 text

*.kt Frontend Native Backend LLVM bitcode generator IR JS Backend JVM Backend IR Generator *.so *.js *.class Syntax tree + Semantic info Before

Slide 28

Slide 28 text

*.kt Frontend Native Backend LLVM bitcode generator IR JS IR Backend JavaScript generator IR JVM IR Backend JVM bytecode generator IR IR Generator *.so *.js *.class Syntax tree + Semantic info Now

Slide 29

Slide 29 text

*.kt New Frontend Native Backend LLVM bitcode generator IR JS IR Backend JavaScript generator IR JVM IR Backend JVM bytecode generator IR IR Generator *.so *.js *.class FIR Goal

Slide 30

Slide 30 text

Resources ● Mascot ○ https://blog.jetbrains.com/kotlin/2021/10/introducing-the-k otlin-mascot/ ● Kotlin 1.5.x ○ https://kotlinlang.org/docs/whatsnew15.html ○ https://kotlinlang.org/docs/whatsnew1520.html ○ https://kotlinlang.org/docs/whatsnew1530.html ● Kotlin 1.6 ○ https://kotlinlang.org/docs/whatsnew16.html

Slide 31

Slide 31 text

Resources ● Coroutines ○ https://blog.jetbrains.com/kotlin/2021/05/kotlin-coroutines -1-5-0-released/ ○ https://github.com/Kotlin/kotlinx.coroutines/releases/tag/1 .6.0-RC ○ https://github.com/Kotlin/kotlinx.coroutines/releases/tag/1 .6.0-RC2 ● Kotlin Symbol Processing ○ https://github.com/google/ksp

Slide 32

Slide 32 text

Resources ● Multiple platform ○ https://blog.jetbrains.com/kotlin/2021/10/compose-multiplat form-goes-beta/ ○ https://blog.jetbrains.com/kotlin/2021/10/kmm-beta-roadmap- video-highlights/ ● K2 Compiler ○ https://www.youtube.com/watch?v=iTdJJq_LyoY ○ https://www.youtube.com/watch?v=db19VFLZqJM

Slide 33

Slide 33 text

STAR_ZERO STAR-ZERO Thank you [Tokyo]