问题描述
我在类 Object
中找到方法 wait()
。
它是final意味着这个方法不能被覆盖。
任何想法为什么它是最终的?
I find the method wait()
in the class Object
.
It is final which means that this method cannot be overriden.
Any ideas why it's final?
推荐答案
@Flavio - 这实际上是一个非常好的问题。
@Flavio - it's actually a very good question.
你无法覆盖它的原因当然是设计师将其作为最终。
The reason you can't override it, of course, is that the designers made it "final".
这个决定的几个潜在原因:
A couple of potential reasons for this decision:
-
你不希望人们弄乱基础类(类对象)上的基本操作的语义。
You don't want people to mess with the semantics of a fundamental operation on a fundamental class (class "Object").
因为它是最终的 ,编译器可以通过内嵌wait()来优化性能(节省几个周期)
Since it's "final", compilers can optimize performance (save a few cycles) by in-lining "wait()"
final增加了Java对象模型的安全性防止恶意代码利用wait()。
"final" increases the security of the Java object model by preventing malicious code from exploiting "wait()".
这篇关于为什么我不能在Java中覆盖方法wait()?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!