在Java中,术语 final 是指引用,而不 可变
是指对象。将
final修饰符分配给引用意味着它不能更改为指向另一个对象,但是如果对象是可变的,则可以对其进行修改。
例如:
final ArrayList<String> arr = new ArrayList<String>();arr.add("hello"); // OK, the object to which arr points is mutatedarr = null; // Not OK, the reference is final and cannot be reassigned to就像Wikipedia文章中提到的那样,如果您来自C ++,则必须分离出
constinto
final和不可变的概念。



