jdk系统内部也封装了好多可以用Lambda表达式去实现的接口
Predicate(参数T;返回值boolean)(子类IntPredicate、LongPredicate、DoublePredicate)、
Consumer(参数T;返回值void)(子类IntConsumer、LongConsumer、DoubleConsumer)、
Function<T,R>(参数T;返回值R)、
Supplier(参数无;返回值T)、
UnaryOperator<T,T>(参数T;返回值T)、
BinaryOperator<T,T>(参数T,T;返回值T)、
BiFunction<T,U,R>(参数T,U;返回值R)、
BiPredicate<T,U>(参数T,U;返回值boolean)、
BiConsumer<T,U>(参数T,U;返回值void))
public class LambdaTest10 {
public static void main(String[] args) {
int n = getNumber().get();
System.out.println(n);
}
private static Supplier<Integer> getNumber() {
int num = 10;
return () -> {
return num;
};
}
}
//输出:10
public class LambdaTeat11 {
public static void main(String[] args) {
int a = 10;//注意:这个a会提升至final ,不可以执行++或其他操作
Consumer<Integer> c = ele ->{
System.out.println(a);
};
c.accept(1);
}
}
//输出:10