# DLP 代码测试
## 1. 测试代码
使用代码 java-learning-master
## 2. 测试过程
1. 压缩包外发,将文件夹java-learning-master压缩并通过微信等工具外发。
2. 将下列内容粘贴至在线文档(印象笔记等)。
```java
package com.brianway.learning.java8.lambda;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.function.BiFunction;
import java.util.function.Function;
import java.util.function.Supplier;
/**
* Created by brian on 17/2/28.
* 构造函数引用
*/
public class ConstructorReference {
public static void main(String[] args) {
//Apple()的构造函数
Supplier<Apple> c1 = Apple::new;
Apple a1 = c1.get();
System.out.println(a1);
//Apple(int weight)的构造函数
Function<Integer, Apple> c2 = Apple::new;
Apple a2 = c2.apply(110);
System.out.println(a2);
List<Integer> weights = Arrays.asList(7, 3, 4, 10);
List<Apple> apples = map(weights, Apple::new);
System.out.println("list of weights:");
apples.stream().forEach(System.out::println);
//Apple(int weight, String color)的构造函数
BiFunction<String, Integer, Apple> c3 = Apple::new;
Apple a3 = c3.apply("green", 110);
System.out.println(a3);
}
public static List<Apple> map(List<Integer> list,
Function<Integer, Apple> f) {
List<Apple> result = new ArrayList<>();
//TODO
for (Integer e : list) {
result.add(f.apply(e));
}
return result;
}
public static class Apple {
private int weight = 0;
private String color = "";
public String toString() {
return "Apple{" +
"color='" + color + '\'' +
", weight=" + weight +
'}';
}
}
}
```