private int times2 (final int x) {
return x* 2;
}
The method name, times2, is preceded by the private keyword (which we will deal with in Chapter 6, page 171) and the return type int, and is followed by a parameter declaration. The parameter declaration appears in parentheses and looks very like a variable declaration, which, in fact, it is. The final int x is declaring a parameter variable called x that will not be changed in the method. If the final is not present, then the value of the parameter can be changed in the method body. Neither situation is more correct, the right choice depends upon the context; what the method is computing and how it does it. However, in all situations where the parameter remains unchanged in the method it is always best to have the final—the compiler supports our intention of the parameter variable being a constant by checking to ensure that the value is never actually assigned to, issuing an error if it is. (Winder 64)
Winder, Russel. Developing Java Software, 3rd Edition. John Wiley & Sons UK, 122006. VitalBook file.