final specifically means "do not inherit me" (in this context, it has other meaning in different contexts).
The reason for developers to mark the class as final are mainly optimizations. Either they can guarantee that some variables will be specifically of some class and also JIT can take advantage of this as it can avoid more expensive virtual calls and rather inline the methods directly.
I think it is a reasonable request. Of course, the subclass shouldn't be able to override any behavior of the final super class. But the subclass can add its own, independent state and behavior. That is, we could weaken the final class semantics to mean all it methods are final, but the class can still be subclassed. This feature could become useful in some cases.
Many OOP languages have this feature, C# for instance uses "sealed" to accomplish the same thing. In addition to the aforementioned compiler optimisations, it is also useful for enforcing certain constraints on the consumers of (e.g.) a class library where it is undesirable to allow the client code to override certain aspects of the libraries functionality for either security or protection of intellectual property reasons.
Asked in February 2016Viewed 2,262 timesVoted 5Answered 4 times