Final variables
In our case, tmp is a final local variable. The scope of this variable is limited to the block following the if statement, and inside this block, this variable gets a value only once. The block is executed many times during the code execution, and each time the variable gets into scope, it gets a value. However, this value cannot be changed in the block. This may be a bit confusing. You can think about it as having a new tmp each time the block executes. The variable gets declared and has an undefined value and can get a value only once.
Final local variables do not need to get the value where they are declared. You can assign a value to a final variable some time later. It is important that there should not be a code execution ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access