日期:2014-05-20  浏览次数:20634 次

一个关于匿名内部类的问题
Java code

package com.gmx;

public class Test {

/**
 * @param args
 */
public static void main(String[] args) {
final int count = 0;

new Thread(){

@Override
public void run() {
count++;
}

}.start();
}

}





用什么办法能让上面的代码实现 count++ ,匿名内部类中只能使用final类型的数据.

------解决方案--------------------
Java code

public class Test{

 int count = 0;
 Thead t = new Thead(){
  public void run(){
   count++;
  }
 };

 public void doTest(){
  t.start();
 }
 public static void main(String [] args ){
  Test test = new Test();
  test.doTest();
 }
}