2、[简答题] 【函数式接口】 1. 定义一个函数式接口IntCalc,其中抽象方法int calc(int a , int b),使用注解@FunctionalInterface 2. 在测试类中定义static void getProduct(int a , int b ,IntCalc calc), 该方法的预期行为是使用calc得到a和b的乘积并打印结果

2、[简答题] 【函数式接口】
1. 定义一个函数式接口IntCalc,其中抽象方法int calc(int a , int b),使用注解@FunctionalInterface
2. 在测试类中定义static void getProduct(int a , int b ,IntCalc calc), 该方法的预期行为是使用calc得到a和b的乘积并打印结果
3. 测试getProduct(),通过lambda表达式完成需求

////day12_test byzhang 2022/06/10
package day12_test.test02;
//2、[简答题] 【函数式接口】
//1. 定义一个函数式接口IntCalc,其中抽象方法int calc(int a , int b),使用注解@FunctionalInterface
//2. 在测试类中定义static void getProduct(int a , int b ,IntCalc calc), 该方法的预期行为是使用calc得到a和b的乘积并打印结果
//3. 测试getProduct(),通过lambda表达式完成需求

public class Test02 {
    public static void getProduct(int a, int b, IntCalc calc) {
        int product = calc.calc(a,b);
        System.out.println(product);
    }

    public static void main(String[] args) {
        getProduct(2,3,(a,b)->a*b);
    }
}
posted @ 2022-06-10 17:00  不只是智能hello  阅读(104)  评论(0)    收藏  举报