在 Java 中为什么会出现此错误:“属性值必须是常量"? [英] In Java why this error: 'attribute value must be constant'?
本文介绍了在 Java 中为什么会出现此错误:“属性值必须是常量"?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一些 TestNG 代码,我在其中传递了一个名为 timeOut = TESTNG_TEST_TIMEOUT
的测试注释参数.
I have some TestNG code, where I am passing a Test annotation parameter called timeOut = TESTNG_TEST_TIMEOUT
.
@Test(description = "Tests something.", groups = { "regression" },
timeOut = TESTNG_TEST_TIMEOUT, enabled = true)
在我的 TestBase 类中,我有这个成员:
And in my TestBase class I have this member:
public final static long TESTNG_TEST_TIMEOUT = TimeUnit.MINUTES.toMillis(5);
当我使用上述代码行时,我在 Eclipse 中收到属性值必须为常量"错误.
When I use the above line of code, I get a 'attribute value must be constant' error in Eclipse.
但是,如果我像这样简单地定义成员,它会起作用:
But, if I simply define the member like so, it works:
public final static long TESTNG_TEST_TIMEOUT = 300000;
TimeUnit 的使用不是一个常数吗?
Is the use of TimeUnit not a constant?
推荐答案
这个
public final static long TESTNG_TEST_TIMEOUT = 300000;
这个
public final static long TESTNG_TEST_TIMEOUT = TimeUnit.MINUTES.toMillis(5);
不是.
注解成员期望常量表达式(还有一些其他的东西,比如枚举和 Class
文字).
Annotation members expect constant expressions (and a few other things like enums and Class
literals).
这篇关于在 Java 中为什么会出现此错误:“属性值必须是常量"?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文