T
- Type of resultpublic final class Sticky<T> extends Object implements Scalar<T>
This Scalar
decorator technically is an in-memory
cache.
Pay attention that this class is not thread-safe. It is highly
recommended to always decorate it with Synced
.
This class implements Scalar
, which throws a checked
Exception
. This may not be convenient in many cases. To make
it more convenient and get rid of the checked exception you can
use the Unchecked
decorator. Or you may use
IoChecked
to wrap it in an IOException.
final Scalar<Integer> scalar = new StickyScalar<>(
() -> {
System.out.println("Will be printed only once");
return new SecureRandom().nextInt();
}
).value()
There is no thread-safety guarantee.
StickyFunc
Copyright © 2017–2020 Cactoos. All rights reserved.