Message-ID: <1590169353.3957.1422399728638.JavaMail.firstname.lastname@example.org> Subject: Exported From Confluence MIME-Version: 1.0 Content-Type: multipart/related; boundary="----=_Part_3956_1799678306.1422399728638" ------=_Part_3956_1799678306.1422399728638 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Content-Location: file:///C:/exported.html
Immutable objects are ones which don't change after initial crea= tion. Such objects are frequently desirable because they are simple and can= be safely shared even in multi-threading contexts. This makes them great f= or functional and concurrent scenarios. The rules for creating such objects= are well-known:=20
Instead of writing a very long Java or Groovy class mimicking this immut= ability behavior, Groovy lets you just write an immutable class as follow:<= /p>=20=20
All the boiler-plate code is generated at compile-time for you! The exam= ple shows that to instantiate such immutable coordinates, you can use one o= f the two constructors created by the transformation, one taking a map whos= e keys are the properties to set to the values associated with those keys, = and the other taking the values of the properties as parameters. The assert= also shows that equals() was implemented and allows us to properly compare= such immutable objects.=20
You can have a look at the details of the imple= mentation of this transformation. For the record, the Groovy example ab= ove using the @Immutable transformation is over 50 lines of equivalent Java= code.