1
0
mirror of https://github.com/Snailclimb/JavaGuide synced 2025-06-20 22:17:09 +08:00

Update Lambda表达式.md

This commit is contained in:
haiqiang 2019-03-10 22:52:06 +08:00 committed by GitHub
parent e929c8ba24
commit 36147197d7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -60,3 +60,29 @@ public interface Runnable {
- ```Predicate<T> {boolean test(T t);}``` 判断接受一个T对象返回一个布尔值。
- ```Supplier<T> {T get();} 提供者(工厂)``` 返回一个T对象。
- 其他的跟上面的相似大家可以看一下function包下的具体接口。
## 4.变量作用域
```java
public class VaraibleHide {
@FunctionalInterface
interface IInner {
void printInt(int x);
}
public static void main(String[] args) {
int x = 20;
IInner inner = new IInner() {
int x = 10;
@Override
public void printInt(int x) {
System.out.println(x);
}
};
inner.printInt(30);
inner = (s) -> {
//!int x = 10;
//!x= 50; error
System.out.print(x);
};
inner.printInt(30);
}
}
```