Java中 final 的理解

4.12.4. final Variables

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 变量中存的是对数组的引用,那么虽然对数组的操作会改变数组中的元素,但变量始终指的是相同的数组。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值