Skip to content

Overcomplicated singleton #10

@Miha-x64

Description

@Miha-x64

Singleton result = instance;
if (result == null) {
synchronized (Singleton.class) {
result = instance;
if (result == null) {
instance = result = new Singleton(value);
}
}
}
return instance;

Why do you prefer this overcomplicated code instead of concise, simple, thread-safe, and lazy enough

private static final Singleton instance = new Singleton();

?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions