贾亮的专栏

Do something

java中的final


The final keyword can be applied to classes, methods, or fields.
When applied to a class, it means that the class cannot be subclassed. 不能被继承
When applied to a method, it means that the method cannot be overridden by a subclass. 不能被重载
When applied to a field, it means that the field's value must be assigned exactly once in each constructor and can never change after that. 但是这里只针对基本类型有效

While an array reference can be declared as final, the elements of the array cannot. This means that classes that expose public final array fields or return references to those fields through their methods.
Similarly, while an object reference may be declared as a final field, the object to which it refers may still be mutable. If you wish to create immutable objects using final fields, you must prevent references to arrays or mutable objects from escaping from your class.

final string can not be changed with replace method(replace method just reture a new string)

阅读更多
个人分类: Java
想对作者说点什么? 我来说一句

java学习总结-final关键字

2009年03月02日 436B 下载

没有更多推荐了,返回首页

加入CSDN,享受更精准的内容推荐,与500万程序员共同成长!
关闭
关闭