改错

c*s*d*n 2008-10-04 12:40:09
public class test {

private int i;
public void next(){i++;}
public int getValue(){return i;}
public static void main(String[] args){
test tt=new test();
new Thread("Watcher"){

public void run(){
final int val=tt.getValue();
while(true){
if(val%2!=0){
System.out.println(val);
System.exit(0);
}
}
}
}.start();
while(true) tt.next();
}
};
...全文
64 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
xiongwenhua365 2008-10-05
  • 打赏
  • 举报
回复
final Test tt=new Test(); 方法内部的匿名内部类要访问该方法中的变量,必须将其声明为最终类型。
skywt939 2008-10-04
  • 打赏
  • 举报
回复


final test tt=new test();

skywt939 2008-10-04
  • 打赏
  • 举报
回复
恩!楼上说的没错!刚才忽略掉了这点!

public class test extends Thread{}


这个还是要写的, 不然你tt在内部类里面无法调用!
[Quote=引用 1 楼 skywt939 的回复:]
Java code

final test tt=new test();
[/Quote]
西瓜 2008-10-04
  • 打赏
  • 举报
回复
test类没有继承Thread类

62,614

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧