Android Final Variables
15,692
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.
Author by
Dimitris Makris
Updated on June 08, 2022Comments
-
Dimitris Makris almost 2 years
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!
-
Dimitris Makris over 12 yearsSo, except when it is required, assigning final to a variable is a kind of limitation/warning to the developer that he should not change this variable?
-
Blundell over 12 yearsYes it's declaring that this is its final state for a reason.