Open9

Kotlin 1.6 release

PGUMAPGUMA

Stable exhaustive when statements for enum, sealed, and Boolean subjects

when式の分岐チェックがより厳格になりますよというものの模様

sealed class Country(val name: String) {
    object Japan: Country(name = "日本")
    object Sweden: Country(name = "スウェーデン")
}

fun Country.isUsedYen(): Boolean =
    when(this) {
        is Country.Japan -> true
        is Country.Sweden -> false
    }

fun externalFunction(country: Country) {
    // falseに対する分岐がないためコンパイラーが警告を発する=>1.7以降では警告ではなくエラーになる予定の模様
    when(country.isUsedYen()) {
        true -> return
    }

    when(country) {
        // Country.Swedenに対する分岐がないためコンパイラーが警告を発する=>1.7以降では警告ではなくエラーになる予定の模様
        is Country.Japan -> TODO()
    }
}
PGUMAPGUMA

Stable suspending functions as supertypes

coroutinesがまずまだそもそもわかってない...

PGUMAPGUMA

Stable suspend conversions

coroutinesがまずまだそもそもわかってない...

PGUMAPGUMA

Stable instantiation of annotation classes

アノテーションクラスを具象化できるようにする機能が正式導入となった模様
どこで活かせるのか未だわからず...

PGUMAPGUMA

Improved type inference for recursive generic types

型推論が少しパワーアップした模様
詳細が理解できず...

PGUMAPGUMA

Support for annotations on class type parameters

型パラメーターにもアノテーションを付与できるようになった模様
どう活かせるのか?未だイメージわかず...

PGUMAPGUMA

標準ライブライの変更

New readline functions

// Null非許可な読み込み
readLine()!!     // earlier Not Null Assertion Operatorを使った直感的でない記述
readln()         // since 1.6 専用関数で読みやすくなった

// Null許可な読み込み
readLine()       // earlier Null許可・非許可がわかりずらい
readlnOrNull()   // since 1.6 関数名に現れていてわかりやすくなった

Stable collection builders

コレクションの合成とかによく使われるのか?

val x = listOf('b', 'c')
val y = buildList {
    add('a')
    addAll(x)
    add('d')
}

Stable Duration API

https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.time/-duration/

Improvements to the existing API

Comparable.compareTo()で中置記法が使えるようになった