forked from coderbruis/JavaSourceCodeLearning
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLambdaDemo01.java
More file actions
37 lines (30 loc) · 897 Bytes
/
LambdaDemo01.java
File metadata and controls
37 lines (30 loc) · 897 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package com.learnjava.lambda;
/**
* @author bruis
* lambda表达式
*/
public class LambdaDemo01 {
/**
* 打印内部类
*/
interface Printer {
void print(String content);
// void print(String content, String operator);
}
public static void printSomething(String content, Printer printer) {
printer.print(content);
}
public static void main(String[] args) {
// Printer printer = (String content) -> {
// System.out.println(content);
// };
// 去掉参数类型,只有一个参数时可以去掉括号
// Printer printer = (content) -> {
// System.out.println(content);
// };
// 只有一个参数提
// Printer printer = val -> System.out.println(val);
Printer printer = System.out::println;
printSomething("hello lambda", printer);
}
}