Skip to content

Commit

Permalink
Kotlin闭包
Browse files Browse the repository at this point in the history
  • Loading branch information
BetterZhang committed Jun 28, 2017
1 parent ec6f15a commit 43d0bb8
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions src/com/betterzhang/learnkotlin/kotlin/Closure.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.betterzhang.learnkotlin.kotlin

/**
* Created by IntelliJ IDEA.
* Author : Andrew Zhang
* Email : betterzhang.dev@gmail.com
* Time : 2017/06/28 下午 2:18
* Desc : Kotlin闭包
*/

val plus = {x: Int, y: Int -> println("$x plus $y is ${x + y}")}

val hello = {println("Hello Kotlin")}

fun main(args: Array<String>) {

{x: Int, y: Int ->
println("$x plus $y is ${x + y}")
}(2, 8) // 自执行的闭包

plus(2, 8)
hello()

}

0 comments on commit 43d0bb8

Please sign in to comment.