Once a
final
variable has been assigned, it always contains the same value.If a
final
variable holds a reference to an object, then the state of the object may be changed by operations on the object, but the variable will always refer to the same object.This applies also to arrays, because arrays are objects;
if a
final
variable holds a reference to an array, then the components of the array may be changed by operations on the array, but the variable will always refer to the same array.
一旦一个 final
变量被赋值,那么它存的值将保持不变。
如果 final
变量中存的是对对象的引用,那么虽然对象的状态可能会因为对对象的操作而改变,但变量始终指的是相同的对象。
这也适用于数组,因为数组也是对象。
如果 final
变量中存的是对数组的引用,那么虽然对数组的操作会改变数组中的元素,但变量始终指的是相同的数组。