Thread t = new Thread(() -> { for (int i = 0; i < 5; i++) { System.out.println(Thread.currentThread().getName() + " " + i); System.out.println("Hello world"); } }); t.start();
2.Runnable接口Runnable r = () -> { for (int i = 0; i < 5; i++) { System.out.println(Thread.currentThread().getName() + " " + i); System.out.println("Hello world"); } }; r.run();