1.表达式类型检查
public class App {
public static void test(MyInterface inter) {
List list = inter.stratey("hello", new ArrayList());
System.out.println(list);
}
public static void main(String[] args) {
test(new MyInterface() {
@Override
public List stratey(String s, List list) {
list.add(s);
return list;
}
});
test((x, y) -> {
y.add(x);
return y;
});
MyInterface myInterface = (x, y) -> {
y.add(x);
return y;
};
System.out.println(myInterface.stratey("hello", new ArrayList()));
}
}
@FunctionalInterface
interface MyInterface {
R stratey(T t, R r);
}
总结:(x, y) -> {...} -->test(param) --> param = MyInterface --> lambda表达式 --> MyInterface类型,这个就是对于lambda表达式的类型检查,MyInterface接口就是lambda表达式的目标类型(target typing)
2.参数类型检查
总结:(x, y) -> MyInterface.strategy(T t, R r) --> MyInterface inter --> T == String R == List --> lambda --> (x, y) == strategy(T t, R r) -->x==T==String y==R==List,这就是lambda表达式的参数类型检查