java我需要显式导入Thread类吗?
因此,如果我删除import语句,下面这个非常基本的线程示例就不会编译。然而,之前我不必导入Thread类。有没有人经历过这件事,请帮助我
import java.lang.Thread;
class Test {
public static void main(String args[]) {
Thread t = Thread.currentThread();
System.out.println("current thread is "+t);
t.setName("amar");
System.out.println("after name change "+t);
try {
for(int n=5;n>0;n--) {
System.out.println(n);
Thread.sleep(1000);
}
}catch(InterruptedException e) {
System.out.println("main interrupted");
}
}
}
共 (0) 个答案