Last active
August 29, 2015 14:24
-
-
Save stream-iori/bf81de1861f6baa5316d to your computer and use it in GitHub Desktop.
Java8 lambda
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //之前使用匿名类 | |
| new Thread(new Runnable() { | |
| @Override | |
| public void run() { | |
| System.out.println("Hello world !"); | |
| } | |
| }).start(); | |
| //现在使用lambda,无参数 | |
| new Thread(() -> System.out.println("Hello world !")).start(); | |
| //函数接口 | |
| @FunctionalInterface | |
| public interface MyFn { | |
| void method(String arg); | |
| } | |
| //使用函数接口 | |
| MyFn fn = arg -> System.out.println(arg); | |
| fn.method("hello world"); | |
| //给个场景 | |
| Arrays.asList(1,2,3,4).forEach(e -> System.out.println(e % 2 == 0 ? "even" : "odd")); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment