Skip to content

Commit

Permalink
Lambda表达式语法Java、Kotlin对比实现
Browse files Browse the repository at this point in the history
  • Loading branch information
BetterZhang committed Jun 28, 2017
1 parent 6465186 commit 24c4823
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 0 deletions.
24 changes: 24 additions & 0 deletions src/com/betterzhang/learnkotlin/java/Lambda.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.betterzhang.learnkotlin.java;

/**
* Created by IntelliJ IDEA.
* Author : Andrew Zhang
* Email : betterzhang.dev@gmail.com
* Time : 2017/06/28 下午 1:23
* Desc : 匿名函数 ( Lambda 表达式 )
*/
public class Lambda {

public static void main(String[] args) {

new Thread(() -> System.out.println("Hello Java")).start();

new Thread(new Runnable() {
@Override
public void run() {
System.out.println("Hello Java");
}
}).start();
}

}
28 changes: 28 additions & 0 deletions src/com/betterzhang/learnkotlin/kotlin/Lambda.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.betterzhang.learnkotlin.kotlin

/**
* Created by IntelliJ IDEA.
* Author : Andrew Zhang
* Email : betterzhang.dev@gmail.com
* Time : 2017/06/28 下午 1:27
* Desc : description
*/

fun main(args: Array<String>) {

Thread(Runnable {
println("Hello Kotlin")
}).start()

// Kotlin Lambda 表达式语法
val sum = {x: Int, y: Int -> x + y}
val sum1: (Int, Int) -> Int = {x, y -> x + y}
val sum2 = fun(x: Int, y: Int): Int {
return x + y
}

println(sum(2, 8))
println(sum1(3, 9))
println(sum2(5, 12))

}

0 comments on commit 24c4823

Please sign in to comment.