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