题目详情:
6-1 jmu-Java-07多线程-Runnable与匿名类 (10 分)
在Main方法中启动一个线程t1
,该线程输出3行信息:
- 主线程名
- 线程t1的线程名
- 线程t1所实现的所有接口。提示:使用
System.out.println(Arrays.toString(getClass().getInterfaces()));
输出。
注:本题也可使用Lambda表达式实现。
裁判测试程序:
public class Main {
public static void main(String[] args) {
final String mainThreadName = Thread.currentThread().getName();
Thread t1 = /*这里放置你的代码*/
t1.start();
}
}
输入样例:
结尾无空行
输出样例:
主线程名
线程t1的线程名
线程t1所实现的所有接口名
结尾无空行
答案代码:
new Thread(
() -> {
System.out.println(mainThreadName);
System.out.println(Thread.currentThread().getName());
System.out.println(Arrays.toString(Thread.class.getInterfaces()));
}
);