java - 最终类中的非 final方法

标签 java compiler-construction

我的问题很简单:
编译器是否将最终类中的所有方法都视为 final方法?给final类的方法加上final关键字有什么作用吗?

我知道 final 方法有更好的内联机会,这就是我问的原因。

提前致谢。

最佳答案

你是对的,final 类中的所有方法都是隐式 final 的。

See here:

"Note that you can also declare an entire class final. A class that is declared final cannot be subclassed. This is particularly useful, for example, when creating an immutable class like the String class."

And here:

All methods in a final class are implicitly final.

您可能也会感兴趣:Performance tips for the Java final keyword

关于java - 最终类中的非 final方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8766476/

相关文章:

java - Realm 加入列表

compiler-construction - 实现 8051 的函数调用

c++ - 我们是否应该在 C++ 中更喜欢临时变量而不是用户定义的变量

compiler-construction - 第一个编译器是如何编写的?

java - Guice/Morphia,辅助注入(inject)错误

java - 包装 Java 进程的 Windows 服务不时停止

java - 如何在android中使用HTTP post方法解析JSON数据?

java - 从另一个Java类调用 "non-void"方法

c - 在多进程 scanf 的 MPI 中只接受一次输入并将垃圾值分配给其他?

c - 为什么我在C中每次都要指定数据类型给printf()和scanf()?