做最后在Java注释的所有参数 [英] Making all parameters final with an annotation in Java

查看:265
本文介绍了做最后在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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆