注释属性FindBy.xpath的值必须是一个常量表达式 [英] The value for annotation attribute FindBy.xpath must be a constant expression

查看:95
本文介绍了注释属性FindBy.xpath的值必须是一个常量表达式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的问题与发布的内容不同:

My problem is different of what has been posted:

  1. 注释属性的值必须为常量表达式 OR
  2. 注释属性的值最小值必须为常量表达式

我已经将其设置为 final static ,但仍将鼠标悬停在该错误上.
这是我的代码:
Login.java

I have already made it final and static still it is giving me that error on hovering over it.
Here is my code:
Login.java

@FindBy(xpath = Constants.user_email)
public static WebElement user_email;

Constants.java

public static final String user_email= CONFIG.getProperty("user_email");

我试图解决的问题:我将此 public static Properties CONFIG = new Properties(); 更改为此公共静态最终属性CONFIG = new Properties();

What I tried to fix this: I changed this public static Properties CONFIG = new Properties(); to this public static final Properties CONFIG = new Properties();

推荐答案

注释元素值必须在编译时由编译器解析.仅 user_email 是静态final是不够的,它的值必须是编译时间常量,即字符串文字或常量表达式的串联.表达式 CONFIG.getProperty("user_email")直到运行时才可解析,因此不能将其用作注释值.

Annotation element values must be resolvable by the compiler at compile time. It is not enough that user_email is static final, its value must be a compile time constant, i.e. a string literal or a concatenation of constant expressions. The expression CONFIG.getProperty("user_email") is not resolvable until run time, so you can't use it for an annotation value.

Java语言规范:

编译时常量表达式是表示原始类型或String的值的表达式,该值不会突然完成,并且仅使用以下内容组成:

A compile-time constant expression is an expression denoting a value of primitive type or a String that does not complete abruptly and is composed using only the following:

[...]

  • TypeName形式的合格名称(第6.5.6.2节).引用常量变量的标识符(第4.12.4节).

其中常量"是原始类型或String类型的变量,它是最终变量,并使用编译时常量表达式初始化"

Where a "constant variable" is a "variable of primitive type or type String, that is final and initialized with a compile-time constant expression"

(是的,这些定义是循环的,对于字符串,您最终必须在带引号的字符串文字或连接一系列其他常量表达式的表达式中达到最低点.)

(yes, these definitions are circular, and in the case of strings you eventually have to bottom out at a quoted string literal or an expression that concatenates a series of other constant expressions).

这篇关于注释属性FindBy.xpath的值必须是一个常量表达式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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