lombok-pg -

lombok
Annotation Type Singleton


@Target(value=TYPE)
@Retention(value=SOURCE)
public @interface Singleton

Two popular singleton templates.

Since not much code is generated, the annotation also acts as documentation.

With lombok:

 @Singleton
 class MySingleton {
        public MySingleton() {
        }
 }
 
Vanilla Java:
 enum MySingleton {
        INSTANCE;
        MySingleton() {
        }
 
        public static MySingleton getInstance() {
                return INSTANCE;
        }
 }
 

Note: If you don't like the enum approach, try the holder approach using
@Singleton(style = Singleton.Style.HOLDER).


Optional Element Summary
 Singleton.Style style
          Specifies the singleton-style to use, default is ENUM.
 

style

public abstract Singleton.Style style
Specifies the singleton-style to use, default is ENUM.

Default:
lombok.Singleton.Style.ENUM

lombok-pg -

Copyright © 2010-2011 Philipp Eichhorn, licensed under the MIT licence.