RedSpider1 / concurrent

这是RedSpider社区成员原创与维护的Java多线程系列文章。

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

2.1.2节 实现Runnable接⼝ 代码无法通过编译

HaiyangYu1999 opened this issue · comments

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();
    }
}

new Thread(new MyThread()).start();
官网已更新