函数式接口验证
package com.xlg.task.common;
import java.util.HashMap;
public class FunctionalInterfaceTest {
public static void main(String[] args) {
int x = 1;
int y = 2;
String key = "2";
HashMap<String, NoParamConsume> map = new HashMap<>();
map.put("1", () -> get1(x, y));
map.put("2", () -> get2(2, 2, 3));
map.forEach((k, v) -> {
if (k.equals(key)) {
System.out.println(v.apply());
}
});
}
private static Integer get2(Integer x, Integer y, Integer z) {
return 2 * x + y + z;
}
private static Integer get1(Integer x, Integer y) {
return 2 * x + 1 + y;
}
}
@FunctionalInterface
interface NoParamConsume<R> {
R apply();
}
因为相信,所以看见.

浙公网安备 33010602011771号