Skip to content

Commit 3614719

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

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

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

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,3 +60,29 @@ public interface Runnable {
6060
- ```Predicate<T> {boolean test(T t);}``` 判断,接受一个T对象,返回一个布尔值。
6161
- ```Supplier<T> {T get();} 提供者(工厂)``` 返回一个T对象。
6262
- 其他的跟上面的相似,大家可以看一下function包下的具体接口。
63+
## 4.变量作用域
64+
```java
65+
public class VaraibleHide {
66+
@FunctionalInterface
67+
interface IInner {
68+
void printInt(int x);
69+
}
70+
public static void main(String[] args) {
71+
int x = 20;
72+
IInner inner = new IInner() {
73+
int x = 10;
74+
@Override
75+
public void printInt(int x) {
76+
System.out.println(x);
77+
}
78+
};
79+
inner.printInt(30);
80+
inner = (s) -> {
81+
//!int x = 10;
82+
//!x= 50; error
83+
System.out.print(x);
84+
};
85+
inner.printInt(30);
86+
}
87+
}
88+
```

0 commit comments

Comments
 (0)