Skip to content

Commit 38e568c

Browse files
authored
Update Lambda表达式.md
1 parent 3614719 commit 38e568c

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

Java相关/What's New in JDK8/Lambda表达式.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,11 +78,18 @@ public class VaraibleHide {
7878
};
7979
inner.printInt(30);
8080
inner = (s) -> {
81+
//Variable used in lambda expression should be final or effectively final
8182
//!int x = 10;
8283
//!x= 50; error
8384
System.out.print(x);
8485
};
8586
inner.printInt(30);
8687
}
8788
}
89+
输出 :
90+
30
91+
20
8892
```
93+
lambda表达式和内部类一样,对外部变量捕获时,外部变量必须为final或者是最终变量(effectively final)的,也就是说这个变量初始化后就不能为它赋新值,
94+
同时lambda不像内部类/匿名类,lambda表达式与外围嵌套块有着相同的作用域,因此对变量命名的有关规则对lambda同样适用。
95+
## 5.[方法引用]()

0 commit comments

Comments
 (0)