Hacker News new | ask | show | jobs
by teeuwen 784 days ago
I do not see how the final keyword would make a difference in performance at all in this case. The compiler should be able to build an inheritance tree and determine by itself which classes are to be treated as final.

Now for libraries, this is a different story. There I can imagine final keyword could have an impact.

2 comments

But dynamically loaded libraries exist, so even if it knows the class is the most derived version out of all classes that exist in all of the statically-linked code through LTO or something, unless it can see the instantiation site it won't be able to devirtualize the function calls without the class being marked as final.
Only if the complete source code is available to the compiler.