- Jan 6, 2023
- 11
The final keyword in Java is used to qualify local variables and method arguments.
As a result, you won't be able to reassign x and qwerty in the method's body. This technique pushes your code closer to immutability, which is typically regarded as a good thing. But, as indicated in this blog, it tends to clog up code by having "final" appear everywhere. What are your thoughts on the final keyword in Java for local variables and method parameters?
The last local variables are determined by intent and, in my opinion, are less essential. It all depends on what happens.
Code:
public static void foo(final int x) {
final String qwerty = "bar";
}
The last local variables are determined by intent and, in my opinion, are less essential. It all depends on what happens.