所有最终类都是不可变的吗? [英] Are all final class immutable?
本文介绍了所有最终类都是不可变的吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Java中的所有最终类都是不可变的。
字符串和整数都是最终类,两者都是不可变的我相信。
Are all final classes in Java immutable. String and Integer both are final classes and both are immutable i beleive.
推荐答案
否 - 最后一堂课意味着你不能继承它。它与可变性无关。以下类是最终的但是可变的:
No - a final class means you cannot inherit from it. It has nothing to do with mutability. The following class is final yet mutable:
public final class FinalMutable {
int value;
public void setValue(int v) { value=v; }
public int getValue() { return value; }
}
这篇关于所有最终类都是不可变的吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文