[英]How can I use Groovy's properties in Interfaces?
假设我已经在Groovy中定义了一个接口(带有属性),如下所示:
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”的接口一样使用它。
有关特征的更多信息,请参阅http://docs.groovy-lang.org/next/html/documentation/core-traits.html
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.