The static method currentThread() from the type Thread should be accessed in a static way用静态方式存取 怎么操作?public static void main(String[] args){ Thread worker=new Thread(); String name = worker.currentThread().getName(); System.

来源:学生作业学帮网 编辑:学帮网 时间:2024/05/16 19:05:31

The static method currentThread() from the type Thread should be accessed in a static way
用静态方式存取 怎么操作?
public static void main(String[] args){
Thread worker=new Thread();
String name = worker.currentThread().getName();
System.out.println(name);
}
其中 worker.currentThread() 出现该警告.

它指的是currentThread()方法是个静态方法,用静态方式去访问,不是类的实例去调用.
你可以不管它,或者用Thread.currentThread().getName();