【发布时间】:2015-07-02 19:38:50
【问题描述】:
我是 groovy 的新手,我创建了一个包含一些常量的 java 类。
public class test{
public static final constant1 ="hello"
}
现在在我的 groovy 代码中,我只想将这个常量放在一个映射中。
Map<String, String> map1 = new HashMap();
map1.put("hello", test.constant1);
我收到一个 groovy.lang.MissingPropertyException 错误,提示没有此类属性:测试类。
这个错误说明了什么?
【问题讨论】:
-
你
import课堂测试了吗? -
是的,我做了导入类测试
-
请粘贴一个最低限度的完整工作示例 - 以便我们能够重现该异常。此外,请使用错误和堆栈跟踪的确切文本更新问题。
-
将类名大写通常是最佳实践,我怀疑这可能是您的问题。在尝试访问
test.constant1时,在 groovy shell 中运行您的示例会导致unknown property: test。