如何使用Groovy';接口中的属性?
假设我在Groovy中定义了一个接口(带有属性),如下所示:如何使用Groovy';接口中的属性?,groovy,properties,Groovy,Properties,假设我在Groovy中定义了一个接口(带有属性),如下所示: public interface GroovyInterface { int intProperty; boolean boolProperty; } 然后我实现了接口: public class GroovyImplementation implements GroovyInterface { // How do I implement the properties here?
public interface GroovyInterface
{
int intProperty;
boolean boolProperty;
}
然后我实现了接口:
public class GroovyImplementation implements GroovyInterface
{
// How do I implement the properties here?
}
我现在如何在具体类中实现属性@Override
不起作用,因为IntelliJ抱怨我无法覆盖字段。
我已经读过了,但它只说可以在接口中使用属性,但不能说明如何使用。就像在Java中一样,不能在接口中指定属性。但对于Groovy,您可以使用一个特性:
trait GroovyInterface
{
int intProperty
boolean boolProperty
}
然后,您可以像使用“implements GroovyInterface”的接口一样使用它
有关特性的更多信息,请咨询