似乎openJDK 8将非 final
或 static
的私有(private)方法放入 vtable 中。当动态绑定(bind)未用于私有(private)方法(因为它们是用 invokespecial 调用的)或使用时,为什么会这样?
最佳答案
这样做是为了处理一些罕见的情况,即父类(super class)中存在具有相同名称和签名的可重写方法。虽然肯定有改进的地方,但可能针对 JDK 9。
参见 https://bugs.openjdk.java.net/browse/JDK-8024368
Private methods always get a vtable entry to handle backward compatibility with classes - i.e. you can have the same name of a private method local to your class and also inherit a method of from your superclass, which will get inherited around the private method, by your child.
关于java - 为什么 OpenJDK 将私有(private)方法放入 vtable 中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28528192/