Java lambda表达式简化创建线程

就是用来简化创建写法的

格式:

(params) -> expression
(params) -> statement
(params) -> { statements }
new Thread(() -> {
                    for (int b = 0; b < 5; b++) {
                        System.out.println(Thread.currentThread().getName() + " " + b);
                    }
                },"线程1").start();
                new Thread(() -> {
                    for (int b = 0; b < 5; b++) {
                        System.out.println(Thread.currentThread().getName() + " " + b);
                    }
                },"线程2").start();

 

你可能感兴趣的:(JavaSE)