Does a passed final variable in Java stay final on the other side?
final
in this case just means that the local reference file
will be immutable. It has no meaning outside the method. Some coding conventions advocate having all variables final unless they need to be mutable so you'll see code like that when someone is following such guidelines.
Some people might tell you that there's a performance benefit to using final, but that is, in no way, conclusively proven.
The primary benefit of the final
keyword is for the programmer to indicate that a class, method, or field should not be changed.
Bear in mind that declaring a variable final
does not make the referenced object immutable. It just means that the variable cannot have its value reassigned. You can still run methods of the variable file
that could change the File
object internally.
In the two methods you give, I see no value in making the file
variable final
. Some code conventions advocate making all variable final
unless the need to be modified. Some people don't subscribe to that. I consider it a variation on the precautionary principle.