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


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

1 comment
Comment actions Permalink


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


Please sign in to leave a comment.