第1楼 2007-09-23 00:01 1983liukecheng 写道:
编译问题!~~~ 郁闷
class ThreadTest{
public static void main(String args []){
System.out.println("Main start");
new TThread().run();
while(true){
System.out.println("main Thread(): "+Thread.currentThread().getName());
}
}
}
class TThread{
public void run(){
while(true){
System.out.println("TThread: "+Thread.currentThread().getName());
}
}
}
为什么这个能编译过 , 而
class ThreadTest{
public static void main(String args []){
System.out.println("Main start");
while(true){
System.out.println("main Thread(): "+Thread.currentThread().getName());
}
new TThread().run();
}
}
class TThread{
public void run(){
while(true){
System.out.println("TThread: "+Thread.currentThread().getName());
}
}
}
这个却不能编译通过.
第3楼 2007-09-23 03:01 Kimmy★Piggy 写道:
while(true){
System.out.println("main Thread(): "+Thread.currentThread().getName());
}
new TThread().run();
错就错在这两句,while(true)了之后的代码都不会执行,所以编译器找到了new TThread().run()这句代码为不可达到代码,所以编译不通过,很简单的道理~