Implement Java interface in Groovy class

I just started programming in Groovy. I noticed one strange behavior and could not find an explanation for it.

I created the Java interface TestInterface.java

public interface TestInterface {

    public void m1();

}

I created the Groovy class TestG.groovy

class TestG implements TestInterface {

}

I created the 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 with TestG is why I am not getting any error for implementing an abstract method or declaring a class as abstract.

Which is different from java and Groovy, because I needed to implement abstract methods or declare a class abstract in Java, but not Groovy.

+4
source share
1 answer

I know that this question has long come and answered above, but I felt the need to add this.

class TestG implements TestInterface {}

- "java" . groovy ( )

groovy :

def myObject = [m1: {-> doSomething()}] as TestInterface
+4

Source: https://habr.com/ru/post/1607610/


All Articles