Message-ID: <1838828747.1547.1419101115927.JavaMail.email@example.com> Subject: Exported From Confluence MIME-Version: 1.0 Content-Type: multipart/related; boundary="----=_Part_1546_1011050731.1419101115926" ------=_Part_1546_1011050731.1419101115926 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Content-Location: file:///C:/exported.html
Whether the singleton is pattern or an anti-pattern, there are s= till some cases where we need to create singletons. We're used to create a = private constructor, a getInstance() method for a static field or even an i= nitialized public static final field. So instead of writing code like this = in Java:=20 =20
You just need to annotate your type with the @Singleton annotation:= =20 =20
The singleton instance can then simply be accessed with T.instance (dire= ct public field access).=20
You can also have the lazy loading approach with an additional annotatio= n parameter:=20 =20
Would become more or less equivalent to this Groovy class:=20 =20
Lazy or not, once again, to access the instance, simply do T.instance (p= roperty access, shorcut for T.getInstance()).