I've recently been working with Lombok--and I'm wondering it would be possible to provide a class level or method level annotation that adds final to all parameters. For example:
@finalizer
void foo(Bar bar);
Becomes
void foo(final Bar bar);
It is possible. Lombok could do it, there's already the FieldDefaults annotation allowing to make all fields final
by default. Doing this for parameters would be even easier. While final
on fields is something the JVM deals with (by not allowing assignments and issuing write barriers at the end of the constructor), final
on parameters is only a compile time feature.
It isn't possible. Lombok doesn't do it currently and the author's opinion is that it makes no sense.
AFAIK there are tools enforcing final
parameters.
I'd personally be most happy if in Java everything was final
by default and could be overridden by using something like var
. But this idea is coming 20 year too late.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With