3.22. final Parameters
A formal parameter can be declared with the keyword final preceding the parameter declaration in the method definition. A final parameter is also known as a blank final variable; that is, it is blank (uninitialized) until a value is assigned to it, (for example, at method invocation) and then the value in the variable cannot be changed during the lifetime of the variable (see also the discussion in Section 4.10, p. 146). The compiler can treat such blank final variables as constants for code optimization purposes. Whether a formal parameter is declared as final, does not affect the caller's code.
The definition of method calcPrice() from Example 3.3 is shown below, with the formal parameter pizzaPrice declared as final ...
Get Programmer's Guide to Java™ Certification, A: A Comprehensive Primer, Second Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.