|
lombok-pg - | |||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
| SUMMARY: REQUIRED | OPTIONAL | DETAIL: ELEMENT | |||||||
@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. |
public abstract Singleton.Style style
|
lombok-pg - | |||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
| SUMMARY: REQUIRED | OPTIONAL | DETAIL: ELEMENT | |||||||