编程语言
首页 > 编程语言> > 语言-java-题库

语言-java-题库

作者:互联网

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;
    }
}

 

标签:java,语言,final,Solution,addOne,new,题库,public,String
来源: https://www.cnblogs.com/t1314/p/15765686.html