import java.util.function.Function; public class ApplyExample { public static Integer doubleValue(Integer x) { return x * 2; } public static void main(String[] args) { Function<Integer, Integer> square = x -> x * x; // 定义一个函数,计算输入值的平方 int result = square.apply(5); // 使用apply方法,传入5 System.out.println(result); // 输出25 } }
“相关推荐”对你有帮助么?
-
非常没帮助
-
没帮助
-
一般
-
有帮助
-
非常有帮助
提交