Lambda表达式
public class Test {
public static void main(String[] args) {
fun((a) -> a + 100);
}
static void fun(Function<Integer, Integer> fun) {
System.out.println(fun.apply(10));
}
@FunctionalInterface
static interface Function<T, S> {
S apply(T t);
}
}
一个参数的Function接口
public class Test {
public static void main(String[] args) {
fun((a) -> a + 100);
}
static void fun(java.util.function.Function<Integer, Integer> fun) {
System.out.println(fun.apply(10));
}
}
两个参数的Function接口
public class Test {
public static void main(String[] args) {
fun((a, b) -> a + b + 100);
}
static void fun(java.util.function.BiFunction<Integer, Integer, Integer> fun) {
System.out.println(fun.apply(10, 20));
}
}