我无法将接口添加到groovy枚举。添加接口到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(); – Will
这肯定会在mvn测试中破解。 – Will
错误:(23,1)Groovyc:在非抽象类中不能有抽象方法。类'xxx'必须声明为抽象或者必须实现方法'getDevice()'。 – Will