final修饰符

//map和list对应的是栈中存储的地址,final表示地址不能修改,但是地址对应的内存区域的值是可以修改的。所以在方法中参数是final修饰的,不会出错,因为地址没有改变。

//final:修饰符,表示终态的

public class Demo {
public static void main(String[] args) {
Map map=new HashMap();
test(map);
}

public static void test(final Map map) {//此时定义的是final修饰符;final:修饰符,表示终态的

map.put("a", "qqq");//在map中放入数据

Set set = map.keySet();//将map中的key定义成set集合
for (Iterator iterator = set.iterator(); iterator.hasNext();) {
String key = (String) iterator.next();
String value = (String) map.get(key);
System.out.println(key + ":" + value);
}
}

}

原文地址:https://www.cnblogs.com/sunda847882651/p/9520446.html