public final class Finals extends Object
Modifier and Type | Class and Description |
---|---|
static class |
Finals.CachingSupplier<T>
Supplier implementation proxying another supplier while calculating
its return value at most one time. |
Modifier and Type | Method and Description |
---|---|
static <T> T |
constant(T value)
Returns
value unchanged. |
static <T> Finals.CachingSupplier<T> |
lazy(Supplier<T> supplier)
Returns a new
Supplier that calculates its return value at most one
time. |
public static <T> T constant(T value)
value
unchanged. This prevents compilers from inlining
constants (static final fields). Depending classes referring to the constant
do not need to be recompiled if the constant value changes.
Inlining affects primitive data types and strings.
Usage example:
public static final String CONSTANT_FIELD = constant("constant value");
T
- return typevalue
- valuepublic static <T> Finals.CachingSupplier<T> lazy(Supplier<T> supplier)
Supplier
that calculates its return value at most one
time. Therefore it can be used to create lazy fields.
This implementation is synchronized. supplier
is guaranteed to be
called at max once.
T
- return typesupplier
- value supplierCopyright © 2025. All rights reserved.