普通写法:
代码如下:
package LambdaPack01;public class MyRunnable implements Runnable{@Overridepublic void run() {System.out.println("多线程启动了");}
}
package LambdaPack01;public class LambdaDemo01 {public static void main(String[] args) {MyRunnable my = new MyRunnable();Thread t = new Thread(my);t.start();}}
匿名内部类:
代码如下:
package LambdaPack01;public class LambdaDemo01 {public static void main(String[] args) {
// MyRunnable my = new MyRunnable();
// Thread t = new Thread(my);
// t.start();new Thread(new Runnable() {@Overridepublic void run() {System.out.println("多线程启动了");}}).start();}}
Lambda表达式:
代码如下:
package LambdaPack01;public class LambdaDemo01 {public static void main(String[] args) {
// MyRunnable my = new MyRunnable();
// Thread t = new Thread(my);
// t.start();// new Thread(new Runnable() {
// @Override
// public void run() {
// System.out.println("多线程启动了");
// }
// }).start();new Thread(()->{System.out.println("多线程启动了");}).start();}}