日記
寒いね
今日書いたコード
fun main() { // val triple: (Int) -> Int = { a: Int -> a * 3 } val triple: (Int) -> Int = { print(it) it * 3 } println(triple(5)) // println(hoge(5)) } fun hoge(it: Int): Int { print(it) it * 3 // A 'return' expression required in a function with a block body ('{...}') }
感想
Kotlinだとラムダ式というのが正式っぽい.
ラムダ式だけ暗黙的に最後の式が返り値になってそう.Kotlinはラムダ式と関数が別物なのか?*1
The last expression in the lambda is the return value. https://developer.android.com/codelabs/basic-android-kotlin-training-collections?continue=https%3A%2F%2Fdeveloper.android.com%2Fcourses%2Fpathways%2Fandroid-basics-kotlin-unit-3-pathway-1%23codelab-https%3A%2F%2Fdeveloper.android.com%2Fcodelabs%2Fbasic-android-kotlin-training-collections#3