2.1.2节 实现Runnable接⼝ 代码无法通过编译
HaiyangYu1999 opened this issue · comments
HaiyangYu commented
public class Demo {
public static class MyThread implements Runnable {
@Override
public void run() {
System.out.println("MyThread");
}
}
public static void main(String[] args) {
new MyThread().start(); // Runnable接口中只有run()方法, 所以Mythread类中没有start()方法
// Java 8 函数式编程,可以省略MyThread类
new Thread(() -> {
System.out.println("Java 8 匿名内部类");
}).start();
}
}