简体   繁体   English

无法在Runnable中实现run()

[英]cannot implement run() in Runnable

public class Reader extends Thread{

...

    public static void run()throws InterruptedException{

        Monitor mon = new Monitor();

            for(int i = 0; i <10; i++)
            {
                mon.MonEntry();



                Read("file.txt");

                mon.MonExit();
            }

    }
}

I cannot use extends Thread for some reason because it says: cannot implement run() in Runnable. 我出于某种原因无法使用extends Thread,因为它说:无法在Runnable中实现run()。 I don't see what I did wrong? 我不明白我做错了什么? When we call extends Thread instead of implement Runnable shouldn't we be able to use our own implementation of run() for starting threads? 当我们调用extends而不是实现Runnable时,我们是否应该能够使用我们自己的run()实现来启动线程?

It is just a public void. 这只是一个公共空白。 No static. 没有静电。

Please, have a look at the documentation . 请看一下文档 It clearly shows that it is public void :-) 它清楚地表明它是public void :-)

Also, avoid the name Reader because there is a class in java.io package which is named Reader and using names that are already present in Java packages is discouraged :) 另外,避免使用名称Reader因为在java.io包中有一个名为Reader的类,并且不鼓励使用已存在于Java包中的名称:)

Thread类里面的run方法不是静态的

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM