Groovy is a flexible, dynamic language on the Java platform with features like Python, Ruby and Smalltalk, and groovy guarantees that these features are used by Java developers like Java syntax;
Here's a simple example of groovy dynamics, a feature I've come into contact with and like, groovy
1. In Java, the following JUnit test code executes through
int method (String arg) {
return 1;
}
int method (Object arg) {
return 2;
}
void Dotest () {
object o = "Object";
int result = Method (o);
Assert.assertequals (2, result); Expected return value is 2 ha
}
2. In groovy, the following JUnit test code executes
int method (String arg) {
return 1
}
int method (Object arg) {
return 2
}
void Dotest () { C19/>object o = "Object"
int result = Method (o)
assert.assertequals (1, result)//Expected return value is 1 ha
}
Here's the start of configuring groovy for our project in idea. I use a Web project based on SPRING_MVC to import the project;
There are two ways to add the groovy framework support
Method One: Right-click on the item select "Add Framework support ...", tick groovy, and select the groovy dependency package that was introduced on the right-hand side (you can download the source package from the official webpage to local and unzip it, then configure the introduction here);
Method Two: If the project to be added groovy is based on Maven, it is good to add the required dependencies directly in the Pom file;
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-all< /artifactid>
<version>2.4.4</version>
</dependency>
Then you can add any groovy code to the project, and for more syntax features of Groovy please refer to: Syntax