net.sf.javagimmicks.util8.ConstantSupplier Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of gimmicks Show documentation
Show all versions of gimmicks Show documentation
Utility classes, APIs and tools for Java
package net.sf.javagimmicks.util8;
import java.util.Objects;
import java.util.function.Supplier;
/**
* An implementation of {@link Supplier} which holds a constant object of the
* required type and returns it upon every call to {@link #get()}
*/
public class ConstantSupplier implements Supplier
{
private final E _value;
/**
* Create a new instance for the given constant value
*
* @param value
* the value to use for every creation call
*/
public ConstantSupplier(final E value)
{
_value = value;
}
@Override
public E get()
{
return _value;
}
@Override
public String toString()
{
return Objects.toString(get());
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy