Assuming s not assigned for its declaration, then yes, s is “virtually final,” according to JLS, section 4.12.4 , which defines this, in your case:
Some variables that are not declared final are considered virtually final:
A local variable whose declarator has an initializer (§14.4.2) is actually final if all of them are true:
Not declared final .
In an assignment expression, it does not occur as the left side (§15.26). (Note that the local variable declarator containing the initializer is not an assignment expression.)
It never occurs as the operand of a prefix or postfix increment or decrement (§15.14, §15.15).
A local variable in which the declarator does not have an initializer is actually final if all of them are true:
It is not declared final.
Whenever this occurs as the left side in an assignment expression, it is definitely not assigned and definitely not assigned before the assignment; that is, it is definitely not assigned and definitely not assigned after the right side of the assignment expression (§16 (Defined assignment)).
This never happens as the operand of a prefix or postfix increment or decrement.
You assign s during the declaration and are an object; it cannot be an operand of the increment or decrement operator, therefore it is final.
It also states that a variable can be effectively final in another case, if it is not assigned when it is declared, because it is only assigned once, it is definitely not assigned before the declaration and is definitely assigned after the declaration.
In addition, the end of this section states:
If the effective variable is final , adding the final modifier to its declaration will not result in compile-time errors. Conversely, a local variable or parameter declared final in the actual program becomes final if the final modifier is removed.
You must explicitly specify final without causing a compiler error. If so, this is truly final.
source share