Xtend comes with annotations that help to steer the compilation process. These annotations reside in the org.eclipse.xtend.lib plug-in/jar which must be on the classpath of the project containing the Xtend files.
For fields that are annotated as @Property, the Xtend compiler will generate a Java field, a getter and, if the field is non-final, a setter method. The name of the Java field will be prefixed with an _ and have the visibility of the Xtend field. The accessors methods are always public. Thus, an Xtend field
@Property String name
will compile to the Java code
private String _name;
public String getName() {
return this._name;
}
public void setName(final String name) {
this._name = name;
}
The annotation @Data, will turn an annotated class into a value object class. A class annotated with @Data has the following effect:
Example:
@Data class Person {
String firstName
String lastName
}