1、[简答题] 【函数式接口】 1. 定义一个函数式接口CurrentTimePrinter,其中抽象方法void printCurrentTime(),使用注解@FunctionalInterfaceime()

1、[简答题] 【函数式接口】
1. 定义一个函数式接口CurrentTimePrinter,其中抽象方法void printCurrentTime(),使用注解@FunctionalInterface
2. 在测试类中定义static void showLongTime(CurrentTimePrinter timePrinter),该方法的预期行为是使用timePrinter打印系统当前毫秒值
3. 测试showLongTime(),通过lambda表达式完成需求

参考答案:

TimePrinter接口:
@FunctionalInterface
public interface CurrentTimePrinter
{
void printCurrenTime();
}
测试类:
public class Test01 {
public static void main(String[] args) {
showLongTime(()->System.out.println(System.currentTimeMillis()));
}

public static void showLongTime(CurrentTimePrinter timePrinter){
timePrinter.printCurrentTime();
}
}

posted @ 2022-06-10 16:43  不只是智能hello  阅读(32)  评论(0编辑  收藏  举报