// 

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())

}
// 5
Result: 1
Result: 2
Result: 3
Result: 4
Result: 5
Yahoo! JAPANとKotlin
Yahoo! JAPANとKotlin
Yahoo! JAPANとKotlin
Yahoo! JAPANとKotlin

Yahoo! JAPANとKotlin

  • 5.
  • 7.
    // 
 val square:(Int) -> Int = { it * it }
 square(2) //-> 4 
 // 
 fun sort(algorithm:(Int, Int) -> Boolean) {
 //...
 }
 sort { first, second -> first < second }
  • 8.
  • 9.
    //null 
 var notNullable:String= "world"
 notNullable = null // //null var nullable:String? = "hello"
 nullable = null // if ? 
 println(nullable?.capitalize())
  • 11.
    fun String.twice() ="${this}, ${this}"
 
 println("hello".twice())
 // -> hello, hello
  • 19.
  • 24.
    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())
 } // 5 Result: 1 Result: 2 Result: 3 Result: 4 Result: 5