diff --git a/pom.xml b/pom.xml index 97e2f3a..c74ee71 100644 --- a/pom.xml +++ b/pom.xml @@ -17,6 +17,7 @@ 1.1.1 1.3.2 utf-8 + 1.8 @@ -258,8 +259,8 @@ org.apache.maven.plugins maven-compiler-plugin - 1.7 - 1.7 + ${jdk.verion} + ${jdk.verion} ${file_encoding} diff --git a/resources/idea/mac-settings.jar b/resources/idea/mac-settings.jar index 0d958ea..757b3aa 100644 Binary files a/resources/idea/mac-settings.jar and b/resources/idea/mac-settings.jar differ diff --git a/src/main/java/osc/git/eh3/LambdaTest.java b/src/main/java/osc/git/eh3/LambdaTest.java new file mode 100644 index 0000000..3602228 --- /dev/null +++ b/src/main/java/osc/git/eh3/LambdaTest.java @@ -0,0 +1,50 @@ +package osc.git.eh3; + +import java.util.Arrays; +import java.util.List; + +/** + * Created by lixiangrong on 2017/6/20. + */ +public class LambdaTest { + public static void main(String[] args) { + // @FunctionalInterface 函数式接口 + new Thread(new Runnable() { + @Override + public void run() { + System.out.println("hello thread"); + } + }).start(); + new Thread(() -> System.out.println("hello lambda")).start(); + + List list = Arrays.asList(1, 2, 3, 4, 5, 6, 7); + + System.out.println("------------打印集合元素----old way----"); + for (Integer n : list) { + System.out.println(n); + } + System.out.println("------------打印集合元素----new way----"); + // list.forEach(n -> System.out.println(n));// list.forEach((Integer n) -> {System.out.println(n)}); + list.forEach(System.out::println); + + System.out.println("------------求平方----old way------"); + for (Integer n : list) { + int x = n * n; + System.out.println(x); + } + System.out.println("------------求平方-----new way-----"); + // list.stream().map(n -> n * n).forEach(x -> System.out.println(x)); + list.stream().map(n -> n * n).forEach(System.out::println); + + System.out.println("------------求平方和----old way------"); + int sum = 0; + for (Integer n : list) { + int x = n * n; + sum = sum + x; + } + System.out.println(sum); + System.out.println("------------求平方和-----new way-----"); + System.out.println(list.stream().map(n -> n * n).reduce((x, y) -> x + y).get()); + + } +}