Hello, is there a way to make all methods in a class final that are not overridden?

Answered

This would be really nice for performance reasons. Amazingly, HotSpot can inline methods that are not final and then un-inline them if a class gets loaded that overrides the method, but it's not guaranteed when it will do this and making this guess consumes some effort. HotSpot could inline more easily when methods are final. In addition, it can be good to make methods final that are not extension points. In some classes that are extended, it could be nice to make only a few methods non-final. It could be helpful in that case to make them all final and then think about which methods should be overridable. Thanks -- Jon

0
1 comment

Hello, 

Please see the inspection Java | Declaration redundancy | Declaration can have final modifier. Does it help to solve your task? Thank you 

0

Please sign in to leave a comment.