実装だけでなく宣言も共有可能
// Common module
expect fun hello()
// JVM module
actual fun hello() { println("Hello, JVM!") }
// JS module
actual fun hello() { println("Hello, JS!") }
Slide 8
Slide 8 text
実装だけでなく宣言も共有可能
// Common module
expect fun hello()
// JVM module
actual fun hello() { println("Hello, JVM!") }
// JS module
actual fun hello() { println("Hello, JS!") }
Slide 9
Slide 9 text
マルプラ・プロジェクト始め方
Slide 10
Slide 10 text
アノテーション引数における配列リテラル
annotation class Foo(val value: Array)
@Foo(arrayOf("hoge", "fuga"))
class Bar
@Foo(["hoge", "fuga"])
class Bar
bound callabel referenceの改善
object Foo {
fun square(n: Int) = n * n
fun squareOf4() = (this::square)(4)
fun squareOf5() = 5.let(this::square)
}
Slide 16
Slide 16 text
bound callabel referenceの改善
object Foo {
fun square(n: Int) = n * n
fun squareOf4() = (this::square)(4)
fun squareOf5() = 5.let(this::square)
}
object Foo {
fun square(n: Int) = n * n
fun squareOf4() = (::square)(4)
fun squareOf5() = 5.let(::square)
}
Slide 17
Slide 17 text
bound callabel referenceの改善
object Foo {
fun square(n: Int) = n * n
fun squareOf4() = (this::square)(4)
fun squareOf5() = 5.let(this::square)
}
object Foo {
fun square(n: Int) = n * n
fun squareOf4() = (::square)(4)
fun squareOf5() = 5.let(::square)
}
←コンンパイラが死ぬ
(1.2.0-rc-39)
Slide 18
Slide 18 text
型推論の改善
// API level 26以降
fun findViewById(id: Int): T
val btn1: Button = findViewById(R.id.btn1) OK
val btn2 = findViewById(R.id.btn2) OK
val btn3 = findViewbyId(R.id.btn3) as Button NG
1.2より前のバージョン
Slide 19
Slide 19 text
型推論の改善
// API level 26以降
fun findViewById(id: Int): T
val btn1: Button = findViewById(R.id.btn1) OK
val btn2 = findViewById(R.id.btn2) OK
val btn3 = findViewbyId(R.id.btn3) as Button OK
1.2から、この推論がで
きるようになった
Slide 20
Slide 20 text
スマートキャストの改善その1
fun main(args: Array) {
val name: String? = null
if (args.isNotEmpty()) name = args[0]
run {
if (name != null) name.length()
}
}
Slide 21
Slide 21 text
スマートキャストの改善その1
fun main(args: Array) {
val name: String? = null
if (args.isNotEmpty()) name = args[0]
run {
if (name != null) name.length()
}
}
1.2より前: NG → 1.2: OK
Slide 22
Slide 22 text
スマートキャストの改善その2
val app = getApplication()
val session = (app as? MyApp)?.login()
if (session != null) {
app.myAppMethod()
}
Slide 23
Slide 23 text
スマートキャストの改善その2
val app = getApplication()
val session = (app as? MyApp)?.login()
if (session != null) {
app.myAppMethod()
}
1.2より前: NG → 1.2: OK