Let's say I have defined an Interface in Groovy (with properties) like this:
public interface GroovyInterface
{
int intProperty;
boolean boolProperty;
}
Then I implement the Interface:
public class GroovyImplementation implements GroovyInterface
{
// How do I implement the properties here?
}
How would I now implement the properties in the concrete class? @Override
doesn't work, since IntelliJ complains that I can't override a field.
I've read this similar question, but it only says that it is possible to use properties in an Interface, but not how.
Like in Java you cannot specify properties in an interface. But with Groovy you can use a trait for that:
trait GroovyInterface
{
int intProperty
boolean boolProperty
}
You can then use it exactly like an interface with "implements GroovyInterface".
For more information on traits consult http://docs.groovy-lang.org/next/html/documentation/core-traits.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With