I was reading the source code of TextView and I met this code snippet:
RectF mTmpRectF = new RectF();
float[] mTmpOffset = new float[2];
ExtractedTextRequest mExtracting;
final ExtractedText mTmpExtracted = new ExtractedText();
So, there they define mTmpExtracted as final, but not mTmpRectF.
I have read this What does "final" do if you place it before a variable? where there is analyzed when to use final.
Thus since both objects (mTmpRectF & mTmpExtracted) could be final in this specific case, is there any other reason (i.e. performace, etc) that only one is set to final or it is just a developer code-style?
Thanks!
You can declare a variable in any scope to be final. . The value of a final variable cannot change after it has been initialized. Such variables are similar to constants in other programming languages.
Final variables If a variable is declared with the final keyword, its value cannot be changed once initialized.
August 2022) In the Java programming language, the final keyword is used in several contexts to define an entity that can only be assigned once. Once a final variable has been assigned, it always contains the same value.
In Java, non-static final variables can be assigned a value either in constructor or with the declaration. But, static final variables cannot be assigned value in constructor; they must be assigned a value with their declaration.
I would say the extractedText has been set to final so it cannot be modified after it has been extracted, where as the coder is not bothered if the rectangle get's modified.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With