From 36147197d7d5de1809b872d8a654719e26653df8 Mon Sep 17 00:00:00 2001 From: haiqiang <43314997+Goose9527@users.noreply.github.com> Date: Sun, 10 Mar 2019 22:52:06 +0800 Subject: [PATCH] =?UTF-8?q?Update=20Lambda=E8=A1=A8=E8=BE=BE=E5=BC=8F.md?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../What's New in JDK8/Lambda表达式.md | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/Java相关/What's New in JDK8/Lambda表达式.md b/Java相关/What's New in JDK8/Lambda表达式.md index bf27300f..a7ef7f93 100644 --- a/Java相关/What's New in JDK8/Lambda表达式.md +++ b/Java相关/What's New in JDK8/Lambda表达式.md @@ -60,3 +60,29 @@ public interface Runnable { - ```Predicate {boolean test(T t);}``` 判断,接受一个T对象,返回一个布尔值。 - ```Supplier {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); + } +} +```