Final Method
There are two reasons to declare the method as final. The first is that you know that the function provided by this method has met your requirements and does not need to be extended, this method cannot be overwritten by any class inherited from this class, but inheritance can still inherit this method, that is, it can be used directly. The second is to allow the compiler to convert all calls to this method into an inline (in-line) Call mechanism, which will allow you to directly Insert the method subject to the call when calling the final method, instead of making routine method calls, such as saving breakpoints and pushing stacks, this may cause yourProgramEfficiency is improved. However, when your method subject is very large or you call this method in multiple placesCodeIt will expand rapidly, but may affect efficiency. Therefore, use final for method definition with caution. Girl, hope you can understand
Final class
When using final on a class, you need to consider it carefully. Because a final class cannot be inherited by anyone, it means that this class is a leaf class in an inheritance tree, in addition, such designs have been considered perfect without modification or expansion. For members in the final class, you can define it as final or not final. For methods, because the class is final, they naturally become final. You can also explicitly add a final to the methods in the final class, but this is obviously meaningless.