Is there any performance reason to declare method parameters final in Java? -
is there performance reason declare method parameters final in java?
as in:
public void foo(int bar) { ... }
versus:
public void foo(final int bar) { ... }
assuming bar
read , never modified in foo()
.
the final keyword not appear in class file local variables , parameters, cannot impact runtime performance. it's use clarify coders intent variable not changed (which many consider dubious reason usage), , dealing anonymous inner classes.
there lot of argument on whether final modifier on method has performance gain since methods inlined optimizing compiler @ runtime anyway, regardless of modifier. in case should used restrict overriding of method.
Comments
Post a Comment