Singleton (Groovy 4.0.15)

Package: groovy.lang

## [Java] Annotation Type Singleton

- groovy.lang.Singleton

-     @Documented
      @Retention(RetentionPolicy.SOURCE)
      @Target({ElementType.TYPE})
      @GroovyASTTransformationClass("org.codehaus.groovy.transform.SingletonASTTransformation")
      public @interface Singleton

  Class annotation to make a singleton class. The singleton is obtained through normal property access using the singleton property (defaults to "instance"). Such classes can be initialized during normal static initialization of the class or lazily (on first access). To make the singleton lazy use `@Singleton(lazy=true)`. Lazy singletons are implemented with double-checked locking and a volatile backing field. By default, no explicit constructors are allowed. To create one or more explicit constructors use `@Singleton(strict=false)`. This could be used to:

  - provide your own custom initialization logic in your own no-arg constructor - you will be responsible for the entire code (the `@Singleton` annotation becomes merely documentation)
  - provide one or more constructors with arguments for a quasi-singleton - these constructors will be used to create instances that are independent of the singleton instance returned by the singleton property

- - ### Element Summary

    Optional Element Summary
    Type | Name and Description
    --- | ---
    `boolean` | `lazy` Returns: if this singleton should be lazy Default: false
    `String` | `property` Returns: the singleton property name Default: "instance"
    `boolean` | `strict` Returns: if this singleton should have strict semantics Default: true

  - ### Inherited Methods Summary

    Inherited Methods
    Methods inherited from class | Name
    --- | ---
    `class Object` | `wait, wait, wait, equals, toString, hashCode, getClass, notify, notifyAll`

- - ### Element Detail

    - #### public boolean lazy

      Returns:
        if this singleton should be lazy
      Default:
        false

    - #### public String property

      Returns:
        the singleton property name
      Default:
        "instance"

    - #### public boolean strict

      Returns:
        if this singleton should have strict semantics
      Default:
        true