Programmer's Guide to Java™ Certification, A: A Comprehensive Primer, Second Edition
by Khalid A. Mughal, Rolf W. Rasmussen
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 ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access