<!DOCTYPE html><html><head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  </head>
  <body>
    <p>Hi Mikhail,<br>
      you are correct LazyConstant aims at the 80% use case, which is
      more similar to Kotlin's "lazy" keyword.</p>
    <p>As stated here:</p>
    <p><a class="moz-txt-link-freetext" href="https://mail.openjdk.org/pipermail/leyden-dev/2025-September/002712.html">https://mail.openjdk.org/pipermail/leyden-dev/2025-September/002712.html</a></p>
    <p>> That said, the quest for a more fundamental building block
      is not over: we now have a clearer idea on how to expose "stable"
      access to regular fields/array elements, using a <span class="moz-txt-underscore"><span class="moz-txt-tag">_</span>new<span class="moz-txt-tag">_</span></span> var handle access mode.
      Initial experiments look indeed promising: such an approach
      doesn't require the allocation of intermediate abstractions, and
      allows clients to decide if they want to pay for synchronization
      or not. <br>
    </p>
    <p>In other words, something else (lower level) will appear at some
      point in the future to "complete" the API. I believe the
      VarHandle-based solution we're exploring should be an even better
      translation target for Kotlin, as with the outlined strategy you'd
      now be in control of whether you need non-plain access,
      synchronization, etc.</p>
    <p>Maurizio<br>
    </p>
    <p><br>
    </p>
    <div class="moz-cite-prefix">On 10/11/2025 15:51, Mikhail Vorobev
      wrote:<br>
    </div>
    <blockquote type="cite" cite="mid:CABOD7SeyZKin1Fwv6tge6VT_xoCxDdydfhqxjQyVQqhLf7JhXA@mail.gmail.com">
      
      <div dir="ltr"><span id="gmail-docs-internal-guid-ccbe8122-7fff-31b3-0387-495363bda6a2">
          <p dir="ltr" style="line-height:1.38;margin-top:0pt;margin-bottom:0pt"><span style="font-size:11pt;font-family:Arial,sans-serif;color:rgb(0,0,0);background-color:transparent;font-variant-numeric:normal;font-variant-east-asian:normal;font-variant-alternates:normal;vertical-align:baseline">Hello
              Amber Team,</span><span style="font-size:11pt;font-family:Arial,sans-serif;color:rgb(0,0,0);background-color:transparent;font-variant-numeric:normal;font-variant-east-asian:normal;font-variant-alternates:normal;vertical-align:baseline"><br>
            </span><span style="font-size:11pt;font-family:Arial,sans-serif;color:rgb(0,0,0);background-color:transparent;font-variant-numeric:normal;font-variant-east-asian:normal;font-variant-alternates:normal;vertical-align:baseline"><br>
            </span><span style="font-size:11pt;font-family:Arial,sans-serif;color:rgb(0,0,0);background-color:transparent;font-variant-numeric:normal;font-variant-east-asian:normal;font-variant-alternates:normal;vertical-align:baseline">I
              write to provide a data point from the Kotlin Evolution
              Team on the design of LazyConstant (previously
              StableValue). In Kotlin, there is a `lateinit var`
              declaration for a variable that is in an uninitialized
              state until it is assigned later during execution, after
              that it behaves like a normal variable. In practice,
              people tend to use such declarations primarily for
              variables with stable semantics, e.g. for injected
              dependencies or Android View bindings:</span></p>
          <br>
          <p dir="ltr" style="line-height:1.38;margin-top:0pt;margin-bottom:0pt"><span style="font-size:11pt;font-family:Arial,sans-serif;color:rgb(0,0,0);background-color:transparent;font-variant-numeric:normal;font-variant-east-asian:normal;font-variant-alternates:normal;vertical-align:baseline">    class
              Application {</span></p>
          <p dir="ltr" style="line-height:1.38;margin-top:0pt;margin-bottom:0pt"><span style="font-size:11pt;font-family:Arial,sans-serif;color:rgb(0,0,0);background-color:transparent;font-variant-numeric:normal;font-variant-east-asian:normal;font-variant-alternates:normal;vertical-align:baseline">        @Inject
              lateinit var service: Service</span></p>
          <p dir="ltr" style="line-height:1.38;margin-top:0pt;margin-bottom:0pt"><span style="font-size:11pt;font-family:Arial,sans-serif;color:rgb(0,0,0);background-color:transparent;font-variant-numeric:normal;font-variant-east-asian:normal;font-variant-alternates:normal;vertical-align:baseline">    }</span></p>
          <br>
          <p dir="ltr" style="line-height:1.38;margin-top:0pt;margin-bottom:0pt"><span style="font-size:11pt;font-family:Arial,sans-serif;color:rgb(0,0,0);background-color:transparent;font-variant-numeric:normal;font-variant-east-asian:normal;font-variant-alternates:normal;vertical-align:baseline">    class
              MyActivity : AppCompatActivity() {</span></p>
          <p dir="ltr" style="line-height:1.38;margin-top:0pt;margin-bottom:0pt"><span style="font-size:11pt;font-family:Arial,sans-serif;color:rgb(0,0,0);background-color:transparent;font-variant-numeric:normal;font-variant-east-asian:normal;font-variant-alternates:normal;vertical-align:baseline">        lateinit
              var view: ImageView</span></p>
          <p dir="ltr" style="line-height:1.38;margin-top:0pt;margin-bottom:0pt"><span style="font-size:11pt;font-family:Arial,sans-serif;color:rgb(0,0,0);background-color:transparent;font-variant-numeric:normal;font-variant-east-asian:normal;font-variant-alternates:normal;vertical-align:baseline">        override
              fun onCreate(...) {</span></p>
          <p dir="ltr" style="line-height:1.38;margin-top:0pt;margin-bottom:0pt"><span style="font-size:11pt;font-family:Arial,sans-serif;color:rgb(0,0,0);background-color:transparent;font-variant-numeric:normal;font-variant-east-asian:normal;font-variant-alternates:normal;vertical-align:baseline">            view
              = findViewById(R.id.image)</span></p>
          <p dir="ltr" style="line-height:1.38;margin-top:0pt;margin-bottom:0pt"><span style="font-size:11pt;font-family:Arial,sans-serif;color:rgb(0,0,0);background-color:transparent;font-variant-numeric:normal;font-variant-east-asian:normal;font-variant-alternates:normal;vertical-align:baseline">        }</span></p>
          <p dir="ltr" style="line-height:1.38;margin-top:0pt;margin-bottom:0pt"><span style="font-size:11pt;font-family:Arial,sans-serif;color:rgb(0,0,0);background-color:transparent;font-variant-numeric:normal;font-variant-east-asian:normal;font-variant-alternates:normal;vertical-align:baseline">    }</span></p>
          <br>
          <p dir="ltr" style="line-height:1.38;margin-top:0pt;margin-bottom:0pt"><span style="font-size:11pt;font-family:Arial,sans-serif;color:rgb(0,0,0);background-color:transparent;font-variant-numeric:normal;font-variant-east-asian:normal;font-variant-alternates:normal;vertical-align:baseline">These
              variables are intended to be initialized at most once and
              never change after that. To cater to such use cases, we
              considered introducing `lateinit val` declaration in some
              form (possibly just as a delegate, similar to how lazy is
              implemented now in Kotlin). </span></p>
          <br>
          <p dir="ltr" style="line-height:1.38;margin-top:0pt;margin-bottom:0pt"><span style="font-size:11pt;font-family:Arial,sans-serif;color:rgb(0,0,0);background-color:transparent;font-variant-numeric:normal;font-variant-east-asian:normal;font-variant-alternates:normal;vertical-align:baseline">StableValue
              was a perfect fit for the implementation of `lateinit
              val`. On the other hand, LazyConstant could not be used to
              express desired semantics (without hacks) due to its
              limited API: it does not allow setting the value directly
              after construction. </span></p>
          <br>
          <p dir="ltr" style="line-height:1.38;margin-top:0pt;margin-bottom:0pt"><span style="font-size:11pt;font-family:Arial,sans-serif;color:rgb(0,0,0);background-color:transparent;font-variant-numeric:normal;font-variant-east-asian:normal;font-variant-alternates:normal;vertical-align:baseline">From
              our point of view, the current LazyConstant API, in
              contrast to StableValue, does not cover a considerable
              part of use cases for variables with stable semantics
              where they are initialized from values available later and
              there is no sensible initializer function that could be
              provided beforehand.</span><span style="font-size:11pt;font-family:Arial,sans-serif;color:rgb(0,0,0);background-color:transparent;font-variant-numeric:normal;font-variant-east-asian:normal;font-variant-alternates:normal;vertical-align:baseline"><br>
            </span><span style="font-size:11pt;font-family:Arial,sans-serif;color:rgb(0,0,0);background-color:transparent;font-variant-numeric:normal;font-variant-east-asian:normal;font-variant-alternates:normal;vertical-align:baseline"><br>
            </span><span style="font-size:11pt;font-family:Arial,sans-serif;color:rgb(0,0,0);background-color:transparent;font-variant-numeric:normal;font-variant-east-asian:normal;font-variant-alternates:normal;vertical-align:baseline">Best
              Regards, Mikhail Vorobev, Kotlin Evolution Team</span></p>
        </span><br class="gmail-Apple-interchange-newline">
      </div>
    </blockquote>
  </body>
</html>