Hi Constantine, and thank you for your feedback.
During the prototyping phase, we tried a large number of various names, one of
which was 'Lazy'. We ultimately went for LazyConstant because it is more
descriptive (after all, a Lazy class, as implemented in many third-party
libraries, does not provide constant folding, at-most-once initialization,
etc.). Another aspect is that it connects to the lazy collections (which also
provide said properties) and also the named picked is relevant to potential
future JDK constructs.
If you want, you can create your own class that is named Lazy and that has the
same properties as LazyConstant::get:
record Lazy<T>(LazyConstant<T> underlying) implements Supplier<T> {
@Override
public T get() { return underlying.get(); }
static <T> Lazy<T> of(Supplier<? extends T> computingFunction) {
return new Lazy<>(LazyConstant.of(computingFunction));
}
}
Best, Per
________________________________
From: core-libs-dev <[email protected]> on behalf of Constantine
Plotnikov <[email protected]>
Sent: Wednesday, September 24, 2025 9:10 PM
To: [email protected] <[email protected]>
Subject: Feedback on JEP draft: Lazy Constants (Second Preview)
Hello!
It is nice to have a more easy to understand name for LazyConstant. However, I
would like it to be simplified further to "Lazy" instead of "LazyConstant". The
name `LazyConstant` is just too long and it will pollute method signatures and
field declarations. While there might be other implementations of a lazy value
concept, this is a good and sensible one and it is what people usually expect
from a lazy value. This is a valid design choice for a lazy value like being a
mutable is a design choice for list type. If people want other lazy semantics,
they could use another package for their package name.
"LazyConstant" is possibly more explicit, but "Lazy" is much better from the
aesthetic point of view. And in both cases people have to learn a new name and
associate semantics with it. Please allow code to be more beautiful.
Best Regards,
Konstantin Plotnikov