1,使用:
//简化写法:
public class Text05 {
public static void main(String[] args) {
//匿名内部类;直接调用start方法启动线程
new Thread(new Runnable() {
@Override
public void run() {
}
}).start();
}
}
//完整写法:
public class Text05 {
public static void main(String[] args) {
Thread thread=new Thread(new Runnable() {
@Override
public void run() {
}
});
thread.start();
}
}
原因:**Thread**的底层:
//自带一个Runnable接口参数
public Thread(Runnable target) {
init(null, target, "Thread-" + nextThreadNum(), 0);
}