做最后在Java注释的所有参数 [英] Making all parameters final with an annotation in Java
问题描述
我最近一直与龙目岛 - 我想知道这将有可能提供类级别或方法级别的注释,增加了最终的所有参数。例如:
@finalizer
无效美孚(酒吧酒吧);
变为
无效美孚(决赛吧吧);
这是可能的。龙目岛可以做到这一点,有已经 FieldDefaults 注释允许让所有领域最后
默认情况下。做这个参数会更容易。而最后
的领域是值得的JVM的交易(不容许的分配,并在构造函数的末尾发出写障碍),最后
的参数仅仅是一个编译时的功能。
这是不可能的。龙目岛没有做它目前和作者的意见是它没有任何意义。
据我所知有工具实施最后
参数。
我个人是会最幸福的,如果在Java中一切最后
默认情况下,可能使用类似 VAR <覆盖/ code>。但是这种想法是未来20今年也晚了。
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.
这篇关于做最后在Java注释的所有参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!