如何在 grails 中使用 Enum(不在域类中)
我想使用枚举来表示一些选择值。在 /src/groovy
文件夹中,在 com.test
包下,我有这个枚举:
package com.test
public enum TabSelectorEnum {
A(1), B(2)
private final int value
public int value() {return value}
}
现在,我尝试从控制器访问它,例如:
TabSelectorEnum.B.value()
但它抛出一个异常:
Caused by: org.codehaus.groovy.runtime.InvokerInvocationException: java.lang.NoClassDefFoundError: Could not initialize class com.test.TabSelectorEnum
我做错了什么?
更新:在我清理并重新编译后,错误代码更改为:
groovy.lang.GroovyRuntimeException: Could not find matching constructor for: com.test.TabSelectorEnum(java.lang.String, java.lang.Integer, java.lang.Integer)
访问 Enum 值的方式似乎有问题,但我不知道是什么。
I want to use an Enum to represent some selection values. In the /src/groovy
folder, under the package com.test
, I have this Enum:
package com.test
public enum TabSelectorEnum {
A(1), B(2)
private final int value
public int value() {return value}
}
Now, I am trying to access it from controller like:
TabSelectorEnum.B.value()
but it throws an exception:
Caused by: org.codehaus.groovy.runtime.InvokerInvocationException: java.lang.NoClassDefFoundError: Could not initialize class com.test.TabSelectorEnum
What am I doing wrong?
Update: After I cleaned and recompiled, the error code changed to:
groovy.lang.GroovyRuntimeException: Could not find matching constructor for: com.test.TabSelectorEnum(java.lang.String, java.lang.Integer, java.lang.Integer)
It seems like there is something wrong in the way accessing the value of the Enum, but I don't know what.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您没有为 int 值定义构造函数:
You didn't define a constructor for the int value: