package test;
import java.util.HashMap;
public class Main {
public static void main(String[] args) {
HashMap<String, Float> M = new HashMap<String, Float>();
M.put("aaaa", (float) 1);
M.put("bbbb", (float) 2);
M.put("cccc", (float) 3);
M.put("dddd", (float) 4);
M.put("eeee", (float) 5);
for(final String s: M.keySet()){
new Thread(new Runnable(){
public void run(){
System.out.println(s);
}
}).start();
}
}
import java.util.HashMap;
public class Main {
public static void main(String[] args) {
HashMap<String, Float> M = new HashMap<String, Float>();
M.put("aaaa", (float) 1);
M.put("bbbb", (float) 2);
M.put("cccc", (float) 3);
M.put("dddd", (float) 4);
M.put("eeee", (float) 5);
for(final String s: M.keySet()){
new Thread(new Runnable(){
public void run(){
System.out.println(s);
}
}).start();
}
}
}
匿名内部类绑定到final变量s的新值。
102

被折叠的 条评论
为什么被折叠?



