I have just started the programming in Groovy. I noticed one strange behavior and unable to find any explanation for the same.
I have created a Java Interface TestInterface.java
public interface TestInterface {
public void m1();
}
I have created a Groovy class TestG.groovy
class TestG implements TestInterface {
}
I have created a Java class TestJ.java
public class TestJ implements TestInterface{
@Override
public void m1() {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
}
My problem is in TestG why I do not get any error to implement abstract method or declare class as abstract.
What does differ in java and groovy as I needed to implement abstract methods or declare class as abstract in Java but not in Groovy.
I know this question has been out for a while and answered above but I felt the need to add this.
class TestG implements TestInterface {}
this is still the "java" way of doing things. Using groovy essentially eliminates the need of implementing interfaces (except just as markup interfaces)
In groovy you would just do this:
def myObject = [m1: {-> doSomething()}] as TestInterface
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