Upload
shoichi-matsuda
View
781
Download
0
Embed Size (px)
Citation preview
//
val square: (Int) -> Int = { it * it } square(2) //-> 4
//
fun sort(algorithm:(Int, Int) -> Boolean) { //... } sort { first, second -> first < second }
//null
var notNullable:String = "world" notNullable = null //
//null
var nullable:String? = "hello" nullable = null
// if ?
println(nullable?.capitalize())
fun String.twice() = "${this}, ${this}"
println("hello".twice()) // -> hello, hello
private fun startLongAsyncOperation(v: Int) = CompletableFuture.supplyAsync { Thread.sleep(1000) "Result: $v" } fun main(args: Array<String>) { val future = async<String> { (1..5).map { await(startLongAsyncOperation(it)) }.joinToString("\n") } println(future.get()) }
// 5Result: 1Result: 2Result: 3Result: 4Result: 5