Skip to main content
A final parameter in Java is a method, constructor, or lambda argument declared with the final modifier, which enforces strict read-only semantics for that specific variable within the lexical scope of the method body. Once the parameter is initialized via the method invocation, the Java compiler prevents any subsequent reassignment of that parameter to a new value or memory address.

Syntax

The final keyword is placed immediately before the data type in the parameter list.

Mechanics and Behavior

The behavior of a final parameter depends strictly on whether the parameter is a primitive data type or a reference type.

1. Primitive Types

When a primitive parameter (e.g., int, double, boolean) is marked final, its literal value is locked. Any attempt to modify the value using assignment operators (=, +=, ++, etc.) results in a compile-time error.

2. Reference Types

When an object reference is marked final, the memory address it points to is locked. You cannot reassign the parameter to point to a newly instantiated object or another existing object. However, the final modifier does not make the object itself deeply immutable. The internal state (fields and properties) of the referenced object can still be mutated if the object’s class exposes mutating methods.

Lambda and Catch Block Parameters

The final modifier can also be applied to parameters within lambda expressions and catch blocks, following the exact same reassignment rules. Lambda Expression:
Catch Block:

Method Overriding and Overloading

The final modifier on a parameter is an implementation detail of the method body, not a part of the method signature. Therefore:
  • Adding or removing final from a parameter does not constitute method overloading.
  • When overriding a method from a superclass or implementing an interface, you can freely add or remove the final modifier on the parameters in the subclass implementation without causing a signature mismatch.
Tired of Poor Java Skills? Fix That With Deep Grasping!Learn More