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

net.sf.javagimmicks.util8.LazySupplier Maven / Gradle / Ivy

There is a newer version: 0.99-alpha1
Show newest version
package net.sf.javagimmicks.util8;

import java.util.function.Supplier;

/**
 * An implementation of {@link Supplier} that creates the instance when it is
 * requested for the first time using another underlying {@link Supplier} which
 * is commonly known as "lazy loading" pattern.
 * 
 * @param 
 *           the type of object the supplier can carry
 */
public class LazySupplier extends AbstractLazySupplier
{
   private E _instance;

   /**
    * Creates a new instance for the given {@link Supplier}
    * 
    * @param supplier
    *           the {@link Supplier} to use for creating the instance
    */
   public LazySupplier(final Supplier supplier)
   {
      super(supplier);
   }

   @Override
   protected E getInstance()
   {
      return _instance;
   }

   @Override
   protected void setInstance(final E instance)
   {
      _instance = instance;
   }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy