Class LazyProvider<T>

  • All Implemented Interfaces:
    javax.inject.Provider<T>

    public abstract class LazyProvider<T>
    extends Object
    implements javax.inject.Provider<T>
    Author:
    Brennan Spies

    Encapsulates the use of the double-checked lock idiom for lazily initializing an instance in a thread-safe way. Subclasses override the init() method to provide the lazily initialized instance.

    • Constructor Detail

      • LazyProvider

        public LazyProvider()
    • Method Detail

      • get

        public T get()
        Gets the instance of T lazily.
        Specified by:
        get in interface javax.inject.Provider<T>
        Returns:
        The instance of T
      • init

        protected abstract T init()
        Must be overriden to initialize the variable reference.
        Returns:
        The newly created instance of T