final修饰对象
public class Solution { public static void main(String[] args) { final String o = new String(); String s = new Solution().addOne(o); System.out.println(o == s);//false } public String addOne(String o) { o = new String();//编译时不报错 return o; } }
public class Solution { public static void main(String[] args) { String o = new String(); String s = new Solution().addOne(o); } public String addOne(final String o) { o = new String();//编译时报错 return o; } }