Package org.cactoos.scalar
Class Constant<T>
- java.lang.Object
-
- org.cactoos.scalar.Constant<T>
-
- Type Parameters:
T
- Type of result
- All Implemented Interfaces:
Scalar<T>
public final class Constant<T> extends Object implements Scalar<T>
Constant value.This
Scalar
represents a constant value which never changes.Contrary to
Sticky
this constant is always pre-computed.This class implements
Scalar
, which throws a checkedException
. Despite that this class does NOT throw a checked exception as it only returns a pre-computed value.Example:
final Scalar<String> constant = new Constant<>("Value"); System.out.print("Constant is always the same: "); System.out.println(constant.value() == constant.value());
This class is thread-safe.
- Since:
- 0.30
- See Also:
Sticky