It seems that openJDK 8 places private methods which are not final
nor static
into vtable. Why is it so when dynamic binding is not used for private methods (since they're invoked with invokespecial) or is it used?
Private methods are useful for breaking tasks up into smaller parts, or for preventing duplication of code which is needed often by other methods in a class, but should not be called outside of that class.
Public instance methods: - All instance methods are public by default. - Use if displaying information or interacting with other classes and/or the client. Private instance methods: - Accessible only from within class scope.
As of Java 9, methods in an interface can be private. A private method can be static or an instance method. Since private methods can only be used in the methods of the interface itself, their use is limited to being helper methods for the other methods of the interface.
This is done to handle some rare situations when an overridable method with the same name and signature exists in a superclass. Though there is definitely a place for improvement, may be, targeted for JDK 9.
See 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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With