[External] : Re: Feedback about LazyConstants API (JEP526)
Anatoly Kupriyanov
kan.izh at gmail.com
Tue Dec 9 12:51:14 UTC 2025
Right, the ScopedValue is another good example I've forgotten. In that case
I am even more inclined to keep the `orElse` as it looks like a repeating
pattern across JDK libraries. Consistency is the way to go!
And maybe even consider having a new interface for the method to make this
pattern explicit?..
I am glad that `orElseSet` is removed, the side-effecting is bad; also in
other parts of JDK we already have `computeIfAbsent` for the same idea. I
did not hear about it, and yeah, sounds like the source of this confusion.
On Tue, 9 Dec 2025 at 12:05, Maurizio Cimadamore <
maurizio.cimadamore at oracle.com> wrote:
>
> On 09/12/2025 11:59, Anatoly Kupriyanov wrote:
> > To be honest, I don't really see why this method causes such confusion.
>
> In part I agree. E.g. when we added this, what we had in mind was just
>
>
> https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/ScopedValue.html#orElse(T)
>
> E.g. other APIs have `orElse` method that return a user-provided value
> if some condition isn't met.
>
> I believe the problem we're discussing here is likely also related to
> the fact that the API used to have a side-effecting `orElseSet`, which
> is now removed, and I wonder if, because of that, folks are reading too
> much into what orElse does?
>
> Maurizio
>
>
--
WBR, Anatoly.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/amber-dev/attachments/20251209/0cfb3388/attachment-0001.htm>
More information about the amber-dev
mailing list