Sometimes you need some βutilityβ classes that contain some static utilities. These classes are not expected to be extended. Thus, developers can make some defensive decisions and mark such classes as "final". I would say that marking a Java class with "final" can lead to minor performance improvements in Hotspot (see https://wikis.oracle.com/display/HotSpotInternals/VirtualCalls ). But, I am sure that it was a design decision, not performance.
You can use final classes if you want to have some objects of immutable value, and also if you want classes to be created only through their factory methods. Objects of immutable value are especially useful when working with concurrency:
public final class MyValueObject { private final int value; private MyValueObject(int value) { this.value = value; } public static MyValueObject of(int value) { return new MyValueObject(value); } }
Using the static factory method, you can hide all of these construction details behind the factory method. Moreover, you can control through the factory the number of instances of this class at runtime - as in single games.
As I said, all these are design decisions. I am sure that there are no remarkable performance gains caused by the final classes.
source share