Hi I like to know why Variables that are local to a method cannot be declared final.. Is there any specific reason? Does it mean are there no local constants in java?
They can be declared final. Your actual problem lies somewhere else.
From the Java specification §4.5.4:
A variable can be declared final. A final variable may only be assigned to once. It is a compile time error if a final variable is assigned to unless it is definitely unassigned (§16) immediately prior to the assignment.
In other words, it is perfectly legal. Moreover, it is considered a best practice to use final
with local variables as much as possible.
Consistently using final with local variables (when appropriate) can be useful as well. [...] A reasonable approach is to use final for local variables only if there is at least one non-final local variable in the method; this serves to quickly distinguish the non-final local variables from the others.
who said we cannot. we can declare. You might have confused with static which cannot be used in methods.