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 inside the block, and it does not exist outside 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; first it is undefined, and then it gets a value once.

Final local variables do not need to get the value where they are declared. You can assign a value to a final variable sometime later. It is important ...

Get Java Projects - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.