This is the old documentation of lombok-pg. The new version can be found in the wiki of the github repository. Take me to the new Version then!

@Singleton

Overview

Detailed Description

With Lombok

01 import lombok.Singleton
02 
03 @Singleton
04 public class SingletonEnumExample {
05   private String s;
06   
07   public void bar() {
08   }
09 }
10 
11 @Singleton(style=Singleton.Style.HOLDER)
12 public class SingletonHolderExample {
13   private String s;
14   
15   public void foo() {
16   }
17 }

Vanilla Java

01 public enum SingletonEnumExample {
02   INSTANCE;
03   
04   public static SingletonEnumExample getInstance() {
05     return INSTANCE;
06   }
07   
08   private String s;
09 
10   public void bar() {
11   }
12 }
13 
14 public class SingletonHolderExample {
15   
16   private static class SingletonHolderExampleHolder {
17     private static final SingletonHolderExample INSTANCE = new SingletonHolderExample();
18   }
19   
20   public static SingletonHolderExample getInstance() {
21     return SingletonHolderExampleHolder.INSTANCE;
22   }
23   
24   private String s;
25   
26   public void foo() {
27   }
28 }

Small print

Smallprint