Is there a way to convert Groovy to Java automatically?

IntelliJ IDEA has a quite decent support for refactoring of groovy code.
It also has a source code level converter from Groovy -> Java. Most of the time it generates code that does not compile, but it may help to get you started with the process of converting the code.
Groovy code:

class HelloWorld {
def name
def greet() { "Hello ${name}" }
int add(int a, int b) {
    return a+b;
}
}

Converted Java code:

public class HelloWorld {
public GString greet() {
    return "Hello " + String.valueOf(name);
}

public int add(int a, int b) {
    return a + b;
}

public Object getName() {
    return name;
}

public void setName(Object name) {
    this.name = name;
}

private Object name;
}

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)