All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.github.shmilyjxs.utils.LazyInitializer Maven / Gradle / Ivy

There is a newer version: 1.37
Show newest version
package io.github.shmilyjxs.utils;

public abstract class LazyInitializer {

    private static final Object NO_INIT = new Object();

    private volatile T object = (T) NO_INIT;

    public T get() {
        T result = object;
        if (result == NO_INIT) {
            synchronized (this) {
                result = object;
                if (result == NO_INIT) {
                    object = result = initialize();
                }
            }
        }
        return result;
    }

    protected abstract T initialize();
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy