Writing less verbose Java Beans with Groovy Beans
Java Beans are very popular among Java developers. A Java Bean is essentially data with little or no behavior (depending on the implementation). Formally, a Java Bean is a Java class that is serializable, has a public no-argument constructor, private fields, and getter and setter methods for accessing the fields. Often, POJO (Plain Old Java Object) and a Java Bean are used interchangeably.
In this recipe, we will show how Groovy can save you from a lot of typing by offering several features for bean class creation built into the language and API.
Getting ready
A typical Java Bean looks like the following code snippet:
public class Student implements Serializable { private Long id; private String name; private String lastName; // more attributes public Student() { // NO-ARGS CONSTRUCTOR } // more constructors public void setId(final Long id) { this.id = id; } public Long getId() { return id; } public...