yahoo! japanとkotlin

Post on 09-Jan-2017

780 Views

Category:

Technology

0 Downloads

Preview:

Click to see full reader

TRANSCRIPT

//

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

top related