禁止“永远不会分配变量”。 IntelliJ IDEA中的警告 [英] Suppress "variable is never assigned" warning in IntelliJ IDEA

查看:1898
本文介绍了禁止“永远不会分配变量”。 IntelliJ IDEA中的警告的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们广泛使用反射来在代码中设置类字段值。这些字段是通过代码访问的,但除了通过反射外,它们永远不会分配所以IDEA显示从未分配警告。如果我要求IDEA取消检查,它会插入

We use reflection extensively to set class field values in our code. The fields are accessed in code but they are never assigned except via reflection. So IDEA displays "is never assigned" warning. If I ask IDEA to suppress the inspection, it inserts

@SuppressWarnings({"UnusedDeclaration"})

但这也会禁止检查字段是否被使用,这是我们不想要的。

but this also disables the check of whether the field is used or not, which we do not want.

无论如何只能禁用未分配支票,只留下未使用检查特定字段吗?

Is it anyhow possible to disable only "not assigned" check and leave "not used" check for specific fields only?

IDEA版本是10.5

IDEA version is 10.5

推荐答案

您可以使用注释将其标记为注入字段。 (类似于它将如何处理 @EJB )。 IntelliJ检查(至少使用版本10.5)允许您配置自己的注释以将字段标记为正在注入。

You could use an annotation to mark it as an injected field. (similar to how it would treat @EJB). The IntelliJ inspections (at least with version 10.5) allow you to configure your own annotations to mark fields as being injected.

从菜单中选择Analyze,Inspect Code然后转到对于未使用的声明检查,您可以配置注释。

Select Analyze, Inspect Code from the menu and then go to the unused declaration inspection and you can configure an annotation.

这篇关于禁止“永远不会分配变量”。 IntelliJ IDEA中的警告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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