IntelliJ IDEA 13.1 Web Help

IntelliJ IDEA supports tight integration between Groovy and Java. For example, you can reference a Java interface from a Groovy script. So doing, you have to keep in mind that anonymous classes are not allowed in Groovy. That's why IntelliJ IDEA suggests a handy quick fix.

To instantiate a Java interface from a Groovy script
  1. Create a Java interface you want to instantiate in a Groovy script. For example:

    GroovyJavaInterface4.png

  2. Open the desired Groovy script for editing, and type the following code:

    GroovyJavaInterface.png

    As you see, IntelliJ IDEA highlights this code as erroneous.

  3. Press Alt+EnterAlt+EnterAlt+EnterAlt+EnterAlt+EnterAlt+EnterAlt+EnterAlt+EnterAlt+Enter, Shift+Alt+J or Ctrl+Shift+MAlt EnterAlt EnterCommand 1 to reveal the quick fix, and click Dynamize invalid interface instantiation.
  4. Depending on the number of methods in the Java interface, the further behavior is different:
    • Java interface contains two or more methods. In this case, you have to specify which methods should be implemented:

      GroovyJavaInterface1.png

      The instantiation code is converted to a map:

      GroovyJavaInterface2.png

    • Java interface contains a single method. In this case, the instantiation code is converted silently to a closure:

      GroovyJavaInterface3.png

See Also

Procedures:

Web Resources: