update code
This commit is contained in:
5
pom.xml
5
pom.xml
@@ -17,6 +17,7 @@
|
|||||||
<mybatis.spring.version>1.1.1</mybatis.spring.version>
|
<mybatis.spring.version>1.1.1</mybatis.spring.version>
|
||||||
<mybatis.generator.core.version>1.3.2</mybatis.generator.core.version>
|
<mybatis.generator.core.version>1.3.2</mybatis.generator.core.version>
|
||||||
<file_encoding>utf-8</file_encoding>
|
<file_encoding>utf-8</file_encoding>
|
||||||
|
<jdk.verion>1.8</jdk.verion>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
@@ -258,8 +259,8 @@
|
|||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-compiler-plugin</artifactId>
|
<artifactId>maven-compiler-plugin</artifactId>
|
||||||
<configuration>
|
<configuration>
|
||||||
<source>1.7</source>
|
<source>${jdk.verion}</source>
|
||||||
<target>1.7</target>
|
<target>${jdk.verion}</target>
|
||||||
<encoding>${file_encoding}</encoding>
|
<encoding>${file_encoding}</encoding>
|
||||||
</configuration>
|
</configuration>
|
||||||
</plugin>
|
</plugin>
|
||||||
|
Binary file not shown.
50
src/main/java/osc/git/eh3/LambdaTest.java
Normal file
50
src/main/java/osc/git/eh3/LambdaTest.java
Normal file
@@ -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<Integer> 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());
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user