一道java题# Java - 爪哇娇娃
b*d
1 楼
Runnable r = new Runnable(){
public void run(){
System.out.println(1);
}
}
Thread t = new Thread(r){
public void run(){
System.out.println(2);
}
};
t.start();
结果是2
我的问题是,这里的anonymous inner class怎么还带参数的?这个参数到底怎么理解?
是否相当于
Class Thread1 extends Thread{}
Thread t = new Thread1(r);
那这样启动线程后为什么不执行runnable的run(), 而是执行overriden的Thread里面的
run()?
非常迷惑
public void run(){
System.out.println(1);
}
}
Thread t = new Thread(r){
public void run(){
System.out.println(2);
}
};
t.start();
结果是2
我的问题是,这里的anonymous inner class怎么还带参数的?这个参数到底怎么理解?
是否相当于
Class Thread1 extends Thread{}
Thread t = new Thread1(r);
那这样启动线程后为什么不执行runnable的run(), 而是执行overriden的Thread里面的
run()?
非常迷惑