How to create closure in Groovy

Closure is an amazingly powerful programming tool, most tricks you can do in a functional language based on closure.

To put it simple, closure is a function without name. Its a value, just like normal variable, can be associate with any valid variable name. You can assign it to local variable name, pass it as parameter, return it from a function.

To put it simple, closure is a function without name. Its a value, just like normal variable, can be associate with any valid variable name. You can assign it to local variable name, pass it as parameter, return it from a .

How to use Groovy enum

Groovy enum is very much like enum in Java, and easier to use. There are many Groovy books out there, but none of them explain it very well, so I decide to learn it by doing. This post creates an Eclipse Groovy project and write some examples to illustrate the usage of Groovy enum.

Groovy strings definition reference

The Groovy string is based on java.lang.String but is more flexible than Java strings.

The double quotes string is exactly like the string you used in Java. The slashy string only escape /, others interpreted literally, is very convenient for defining regular expression.

Reasons to use Groovy

Groovy is a scripting language designed to augment the Java. Its compatible with Java in byte code level, in syntax level, it provide much more flexible than Java like weak type, closure, functional programming.

In general, scripting languages are higher in abstraction level , thus more expressive. It makes the developer can iterate rapidly and boost productivity. Its very easy to manipulate complex component in scripting language. They are not designed to implement the complex components.

In general, scripting languages are higher in abstraction level , thus more expressive. It makes the developer can iterate rapidly and boost productivity. Its very easy to .

Groovy delegate explained

The delegate keyword is widely used in Groovy. This post will explain how to use the delegate keyword.

As the official document :

Groovy regular expression tutorial

The match operator.The operator return true or false depend on the pattern match result. Here is an example:

Program output : true.

Groovy closure

A closure is like an anonymous function in javascript. If you familiar with javascript, the closure is not hard to understand.

The closure also called lambda which first introduced in Lisp. All the dynamic languages like javascript, list, ruby, groovy are based on the concept of lambda calculus. They also called functional programming languages.