<!DOCTYPE html><html><head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<link id="MDHR_textcomplete" rel="stylesheet" href="moz-extension://aa8b6de7-3f78-465d-87c7-03091dbf00e6/vendor/textcomplete.css">
</head>
<body>
<p><br>
</p>
<div class="moz-cite-prefix">On 17/06/2025 13:55, Mickael Istria
wrote:<br>
</div>
<blockquote type="cite" cite="mid:CAFr6BZR6esGFcFDaCK0D-fZDZG+JzTEZovgzDY39m+ZxY48QYA@mail.gmail.com">
<div dir="ltr">
<div>Thanks for your answer.</div>
<div><br>
</div>
<div>> the most minimalistic type to model that would be a
Supplier<T>.</div>
<div><br>
</div>
<div>Indeed. I mentioned Optional, but as the discussion goes,
what could work instead of an Optional would be a constructor
`Supplier.cache(Supplier<T> computer)` that would cache
the computed value. That would be even better than Optional.</div>
</div>
</blockquote>
<p>Note that this is already part of the StableValue API:</p>
<p><a class="moz-txt-link-freetext" href="https://download.java.net/java/early_access/jdk25/docs/api/java.base/java/lang/StableValue.html#supplier(java.util.function.Supplier)">https://download.java.net/java/early_access/jdk25/docs/api/java.base/java/lang/StableValue.html#supplier(java.util.function.Supplier)</a><br>
</p>
<blockquote type="cite" cite="mid:CAFr6BZR6esGFcFDaCK0D-fZDZG+JzTEZovgzDY39m+ZxY48QYA@mail.gmail.com">
<div dir="ltr">
<div><br>
</div>
<div>> a stable value is also this "weird" mutable-only-once
cell, which is effectively a safe wrapper around a JVM @Stable
field.</div>
<div><br>
</div>
<div>OK, for that part, as I have no knowledge of how @Stable
works, I fully trust you.</div>
</div>
</blockquote>
<p>Some pointers:</p>
<p><a class="moz-txt-link-freetext" href="https://github.com/openjdk/jdk/blob/master/src/java.base/share/classes/jdk/internal/vm/annotation/Stable.java">https://github.com/openjdk/jdk/blob/master/src/java.base/share/classes/jdk/internal/vm/annotation/Stable.java</a></p>
<p>(might be useful, as an exercise, to read through the
documentation of that internal annotation, and connect the dots
back to the StableValue API)<br>
</p>
<blockquote type="cite" cite="mid:CAFr6BZR6esGFcFDaCK0D-fZDZG+JzTEZovgzDY39m+ZxY48QYA@mail.gmail.com">
<div dir="ltr">
<div><br>
</div>
<div>> a stable value is very much a mutable beast, so we
need an API that is able to model this at-most-once mutation.
While in most cases the mutation is not really interesting
(because clients are more interested in the laziness aspects)</div>
<div><br>
</div>
<div>Indeed, I admit that my comment was only built on the
use-case of lazily initialized values; which seem to be only a
corner case of StableValue's goal; and I agree that some more
dedicated API to lazily initialized value
(eg `Supplier.cache(Supplier<T> computer)` or
`Optional.supplyNullable(Supplier<T> computer)` still
could make sense independently of StableValue which has a
slightly broader scope.</div>
</div>
</blockquote>
Cheers<br>
Maurizio<br>
<blockquote type="cite" cite="mid:CAFr6BZR6esGFcFDaCK0D-fZDZG+JzTEZovgzDY39m+ZxY48QYA@mail.gmail.com">
<div dir="ltr">
<div><br>
</div>
<div>Thanks again.</div>
<div>Mickael</div>
</div>
</blockquote>
<ul class="dropdown-menu textcomplete-dropdown" style="display: none; position: absolute; z-index: 1000;" contenteditable="false" popover="auto">
</ul>
</body>
</html>