Call Java Classes Form Groovy

Idea: Using Java objects in a scripting language. Sample Java class, just prints a string parameter:
[JAVA]
package test;
public class Test {
public Test(String in){
System.out.println(„Java: „+in);
}
}
[/JAVA]
Groovy class – uses Java class and assigns a string parameter:
[JAVA]
package test;
import test.Test;
class GroovyTest {
static void main(args) {
def c = „groovy: Hallo“;
println(c);
for (i in 0 ..5){
def inte = i.toString();
def x = new test.Test(inte);
}
}
}
[/JAVA]
The output is here:

groovy: Hallo
Java: 0
Java: 1
Java: 2
Java: 3
Java: 4
Java: 5

Step 1 – ok, Step 2 – find project to use.

Schreibe einen Kommentar