<html><head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  </head>
  <body>
    <font size="4"><font face="monospace">More generally, any variable
        that is today used in string concat, String::format, or println
        is a candidate for use in a template.  Many, many of these will
        not be effectively final.</font></font><br>
    <br>
    <div class="moz-cite-prefix">On 6/16/2023 4:23 PM, Remi Forax wrote:<br>
    </div>
    <blockquote type="cite" cite="mid:217671587.83037682.1686947032414.JavaMail.zimbra@univ-eiffel.fr">
      <pre class="moz-quote-pre" wrap="">----- Original Message -----
</pre>
      <blockquote type="cite">
        <pre class="moz-quote-pre" wrap="">From: "Stephen Colebourne" <a class="moz-txt-link-rfc2396E" href="mailto:scolebourne@joda.org"><scolebourne@joda.org></a>
To: "amber-dev" <a class="moz-txt-link-rfc2396E" href="mailto:amber-dev@openjdk.org"><amber-dev@openjdk.org></a>
Sent: Friday, June 16, 2023 10:56:43 AM
Subject: Re: JEP 430 String Templates, some weird scenarios feedback
</pre>
      </blockquote>
      <pre class="moz-quote-pre" wrap="">
</pre>
      <blockquote type="cite">
        <pre class="moz-quote-pre" wrap="">On Thu, 15 Jun 2023 at 23:49, Brian Goetz <a class="moz-txt-link-rfc2396E" href="mailto:brian.goetz@oracle.com"><brian.goetz@oracle.com></a> wrote:
</pre>
        <blockquote type="cite">
          <pre class="moz-quote-pre" wrap="">On 6/15/2023 6:01 PM, Anatoly Kupriyanov wrote:

I understand why it works like that but it still causes some confusion to me, at
least it should be somehow documented:

var val = 1; var template = RAW."val = \{val}"; assert
template.interpolate().equals("val = 1");
val = 2; assert template.interpolate().equals("val = 1");//weird


Yes, a template closes over values, not variables.  We could adopt the same
constraint as we do with lambdas / inner classes -- require that any referenced
variables be effectively final -- but this would likely be quite restrictive
given the typical use cases for string templates.
</pre>
        </blockquote>
        <pre class="moz-quote-pre" wrap="">
FWIW, the example here pushes me to encourage you to adopt effectively
final - and the parallel with lambdas means that no one will be
surprised by choosing effectively final for templates.

I am surprised by the claim that "typical use cases" make this
restrictive. Can you expand? Given that the value is captured not the
variable, it is hard to imagine use cases where effectively final
would be problematic. If there are problematic use cases, perhaps it
would be better to add a language change that gives the developer more
control over effectively final (various options available),
</pre>
      </blockquote>
      <pre class="moz-quote-pre" wrap="">
It will not be convenient for all template processors used for logging/printing.

  LOGGER.trace()."\(thisVariableMustNowBeEffectivelyFinal)";

</pre>
      <blockquote type="cite">
        <pre class="moz-quote-pre" wrap="">
Stephen
</pre>
      </blockquote>
      <pre class="moz-quote-pre" wrap="">
regards,
RĂ©mi
</pre>
    </blockquote>
    <br>
  </body>
</html>