- public static void main(String[] args) {
- final Integer integer = new Integer(1);
- //integer = 2;
- //报错:无法为最终变量integer分配值; 原因:final修饰的基本数据类型不允许更改
-
- final Map<String, String> map = new HashMap<String, String>(){{
- this.put("a", "a");
- }};
- map.put("a","a");//没有报错,final修饰的Map允许的值更改,因为final修饰的是map的引用,而不是内容
- //map = new HashMap<>();//报错:无法为最终变量map分配值 原因:final修饰的map无法修改其引用
- }
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/30046312/viewspace-2150800/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/30046312/viewspace-2150800/