Message-ID: <2004606979.2587.1409581688805.JavaMail.email@example.com> Subject: Exported From Confluence MIME-Version: 1.0 Content-Type: multipart/related; boundary="----=_Part_2586_782218838.1409581688804" ------=_Part_2586_782218838.1409581688804 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Content-Location: file:///C:/exported.html
Another transformation is @Lazy. Sometimes, you want to handle t= he initialization of a field of your class lazily, so that its value is com= puted only on first use, often because it may be time-consuming or memory-e= xpensive to create. The usual approach is to customize the getter of said f= ield, so that it takes care of the initialization when the getter is called= the first time. But in Groovy 1.6, you can now use the @Lazy annotation fo= r that purpose:
In the case of complex computation for initializing the field, you may n= eed to call some method for doing the work, instead of a value like our pet= s list. It is then possible to have the lazy evaluation being done by a clo= sure call, as the following example shows:
There is also an option for leveraging Soft references for garbage colle= ction friendliness for expensive data structures that may be contained by s= uch lazy fields:
The internal field created by the compiler for pets will actually be a S= oft reference, but accessing p.pets directly will return the value (ie. the= list of pets) held by that reference, making the use of the soft reference= transparent to the user of that class.