初级代码挑错并解释原因,欢迎拍砖。。。
[code="java"]public static void main(String[] args)
{
String tmp="Hello";
Thread t = new Thread(){
public void run(){
System.out.println(tmp);
}
};
t.start();
}[/code]
这还用解释吗?
给方法里的内部类的方法传参数,需要用fianl修饰
Cannot refer to a non-final variable tmp inside an inner class defined in a different method
就是这句话的意思
很明显啊
这种错让eclipse来挑比较好:
[color=red]
Cannot refer to a non-final variable tmp inside an inner class defined in a different method
[/color]