Message-ID: <577987564.2923.1411323750091.JavaMail.email@example.com> Subject: Exported From Confluence MIME-Version: 1.0 Content-Type: multipart/related; boundary="----=_Part_2922_1467764779.1411323750090" ------=_Part_2922_1467764779.1411323750090 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()).