简体   繁体   English

在带有 @FindBy 注释的 InellijIdea 中使用的字段“从未分配”

[英]Used field “is never assigned” in InellijIdea with @FindBy annotation

How can I resolve this issue in IntellijIdea?如何在 IntellijIdea 中解决此问题?

在此处输入图像描述

This answer Why no "field is never assigned" warning with @Mock only describe the reason but not offer the resolving.这个答案为什么没有@Mock 的“从未分配字段”警告仅描述原因但不提供解决方案。

To get rid of the warning you can add getter and setter for your fields.要摆脱警告,您可以为您的字段添加 getter 和 setter。

public SelenideElement getOldPassword(){
    return this.oldPassword;
}

public void setOldPassword(SelenideElement oldPassword){
    this.oldPassword = oldPassword;
}

This warning is produced by the "Unused declaration" inspection, which does not know about the @FindBy annotation.此警告是由“未使用的声明”检查产生的,它不知道@FindBy注释。 To teach it, position the text cursor on the name of the field, type Alt + Enter and invoke the Suppress unused warning if annotated by '@FindBy' action.为了教它,position 文本 cursor 在字段名称上,键入Alt + Enter并调用Suppress unused warning if annotated by '@FindBy'操作。 After that it will no longer warn on any field annotated by this annotation.之后,它将不再对该注释注释的任何字段发出警告。

The action will add the intention to an internal "Mark field as implicitly written if annotated by" list.该操作会将意图添加到内部“标记字段为隐式写入,如果注释者”列表。 The setting can also be found in the settings of the inspection by clicking on the Annotations... button under the Entry points tab.通过单击“ Entry points ”选项卡下的“ Annotations...按钮,也可以在检查的设置中找到该设置。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM