Message-ID: <1288576656.11586.1414258567583.JavaMail.firstname.lastname@example.org> Subject: Exported From Confluence MIME-Version: 1.0 Content-Type: multipart/related; boundary="----=_Part_11585_1507672287.1414258567582" ------=_Part_11585_1507672287.1414258567582 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()).