- Java code
package com.gmx;public class Test {/** * @param args */public static void main(String[] args) {final int count = 0;new Thread(){@Overridepublic 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(); }}