Thursday, March 7, 2002 11:21 AM
Although I've never read anything one way or the other, I'm pretty sure that using
can offer very good optimization hints to the JIT.
Think about it: every 'final' class basically means that all methods are 'final'. If a method is final, it cannot be virtual. If it it not virtual, it is a static call. Static calls are pretty fast.
'static' methods are also static calls, because they are always implemented in one place: they cannot be overridden (they are implicitly 'final').
Finally, 'private' methods are also final, since they cannot be overridden, and convert into static calls.
With these hints, the JIT can highly optimize calls to these methods. If the methods are short enough (like in accessors and mutators), then can even be inlined, so that there is no overhead for the method call.
The downside to declaring methods or classes to be final is that you are limiting extensibility. I think it only makes sense to explicitly make a class (or method) final if you have an architectural reason for doing so.
Let the JIT authors do the dirty little tricks. :)