黑马程序员技术交流社区

标题: Thread的一个问题 [打印本页]

作者: Stephen_Chow    时间: 2013-10-30 17:05
标题: Thread的一个问题
本帖最后由 Stephen_Chow 于 2013-10-30 22:49 编辑

想写一个简单的类,调用Thread的这个构造函数:public Thread(Runnable target)。在使用MyEclipse工具中,想用匿名内部类的方法传入一个Runnable的实现类,
即为:new Runnable(){},然后工具提示:Add unimplements methods;CTR+1.工具自动生成了代码:
  1. package thread.tigao.day1;

  2. public class Test {
  3.         public static void main(String[] args) {

  4.                 new Thread(new Runnable() {

  5.                         @Override
  6.                         public void run() {//结果这里出现了红叉:The method run() of type new Runnable(){} must override a superclass method
  7.                                 // TODO Auto-generated method stub
  8.                                 
  9.                         }
  10.                 }).start();
  11.         }
  12. }
复制代码
程序异常信息:
  1. Exception in thread "main" java.lang.Error: Unresolved compilation problem:
  2.         The method run() of type new Runnable(){} must override a superclass method

  3.         at thread.tigao.day1.TraditionalThreadCommunication.main(TraditionalThreadCommunication.java:13)
复制代码
问题如代码中的注释部分,我怎么想都没想明白。明明复写了run方法呀,为什么提示反而说没有呢?有闷死我了,求求了

作者: 烟花雨    时间: 2013-10-30 17:19
没错啊,在我电脑上就没报错,我直接复制的你的代码....并且能运行
作者: miedongdong    时间: 2013-10-30 19:11
有时候eclipse、或者myeclipse是会报错的,你关了重新打开看一下是否还报错,我刚刚在myeclipse上粘贴你的代码是没错的
作者: 黄炳期    时间: 2013-10-30 22:08
程序没错。可以再检查检查
如果问题已经解决,请及时修改主题为“提问结束”
修改主题的链接
http://bbs.itheima.com/thread-89313-1-1.html
作者: Stephen_Chow    时间: 2013-10-30 22:48
黄炳期 发表于 2013-10-30 22:08
程序没错。可以再检查检查
如果问题已经解决,请及时修改主题为“提问结束”
修改主题的链接

我知道答案了,是我的工程的编译器的版本问题:还是很谢谢你。
作者: 黄炳期    时间: 2013-10-30 23:09
Stephen_Chow 发表于 2013-10-30 22:48
我知道答案了,是我的工程的编译器的版本问题:还是很谢谢你。

:lol解决问题后是不是很舒服?早点睡,明天再战斗!




欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/) 黑马程序员IT技术论坛 X3.2