【发布时间】:2016-09-17 03:04:36
【问题描述】:
我无法向 groovy 枚举添加接口。
示例:
接口 DeviceType.groovy
public interface DeviceType{
public String getDevice()
}
枚举 Device.groovy
public enum Devices implements DeviceType {
PHONE{
public String getDevice(){
return "PHONE"
}
}, ALARM {
public String getDevice(){
return "ALARM"
}
}
}
简单测试
public class MainTest(){
public static void main(String [] args) {
System.out.println(Devices.PHONE.getDevice());
//should print phone
}
}
这是伪代码,但是一个很好的例子。 当我将它与 Groovy 一起使用时,我从 IntelliJ 收到一个错误,我需要将接口抽象化。 如果我把它抽象化,maven 不会编译说它不能既是静态的又是最终的。
有什么建议吗?
【问题讨论】:
-
注意:Devices.PHONE.getDevice();
-
这肯定会在 maven 中使用 mvn test 中断。
-
错误:(23, 1) Groovyc: 在非抽象类中不能有抽象方法。必须将类“xxx”声明为抽象类,或者必须实现方法“getDevice()”。
-
请不要评论您自己的问题。改为编辑它以提供缺失的详细信息。