简体   繁体   中英

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

How can I resolve this issue in IntellijIdea?

在此处输入图像描述

This answer Why no "field is never assigned" warning with @Mock only describe the reason but not offer the resolving.

To get rid of the warning you can add getter and setter for your fields.

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. 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. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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