Java -The method sleep(int) is undefined for the type Thread

后端 未结 7 2046
南方客
南方客 2020-12-18 14:46

I\'m getting an error: The method sleep(int) is undefined for the type Thread. I thought the sleep method is in the Thread class in Java.

import java.util.Ra         


        
7条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-18 15:25

    The reason you're getting this is that you've implemented your own Thread class. In your class there is no sleep method.

    First prize would be to avoid using class names that are part of the standard Java libraries.

    If you insists to keep the names, use java.lang.Thread.sleep(...) to specify that you want the Thread class that Java provides.

提交回复
热议问题