<html><head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  </head>
  <body>
    This was received on the -comments list.  It raises a question which
    I realize now was not explicitly discussed with the EG, but which
    was considered in internal discussions: can the result of a string
    template ever be considered a constant expression?  <br>
    <br>
    At first, one might thing that a string template whose embedded
    expressions (and processor) are constant expressions could be a
    constant expression.  The questioner's motivation is that the
    arguments of annotations must be constant expressions, so this would
    enrich the set of things we can put in annotations.  <br>
    <br>
    Unfortunately, the bar for "constant expression" in the JLS is quite
    high (and even that doesn't necessarily get us to annotation
    parameters.)  For String constants, the compiler would "just" have
    to fold the string at compile time -- but it would need need
    permission from the spec to do so, which means we have to specify at
    least part of the "constant folding" story for a very narrow and
    ad-hoc benefit, and which would likely lead to an RFE tail of "can
    you please allow XYZ to be a constant expression".  And for types
    more interesting than String/int/friends, we'd have to do more --
    we'd have to update the specification of annotations to support
    types other than the set of types that currently have an encoding in
    JVMS 4.7.16.  (We explored this for an arguably more valuable use
    case -- method references as annotation parameters -- and while
    there was nothing wrong with that in principle, there was
    significant work in the classfile spec, VM, compiler, and reflection
    (and ASM and friends) to plumb it end to end, and this didn't make
    the priority cut.)  <br>
    <br>
    So the short answer to the question is "no", and the slightly longer
    answer is "you want constant folding, but we're not going to do
    constant folding in little ad-hoc bits."<br>
    <div class="moz-forward-container"><br>
      <br>
      -------- Forwarded Message --------
      <table class="moz-email-headers-table" cellspacing="0" cellpadding="0" border="0">
        <tbody>
          <tr>
            <th valign="BASELINE" nowrap="nowrap" align="RIGHT">Subject:
            </th>
            <td>String templates and constant expressions</td>
          </tr>
          <tr>
            <th valign="BASELINE" nowrap="nowrap" align="RIGHT">Date: </th>
            <td>Sat, 15 Apr 2023 19:46:07 +0200</td>
          </tr>
          <tr>
            <th valign="BASELINE" nowrap="nowrap" align="RIGHT">From: </th>
            <td>Jens Lideström <a class="moz-txt-link-rfc2396E" href="mailto:jens@lidestrom.se"><jens@lidestrom.se></a></td>
          </tr>
          <tr>
            <th valign="BASELINE" nowrap="nowrap" align="RIGHT">To: </th>
            <td><a class="moz-txt-link-abbreviated" href="mailto:amber-spec-comments@openjdk.java.net">amber-spec-comments@openjdk.java.net</a></td>
          </tr>
        </tbody>
      </table>
      <br>
      <br>
      Dear experts and observers,<br>
      <br>
      A recent message in the thread "Revisit the String template
      syntax" compared the Spring property annotation syntax with the
      proposed String template syntax.<br>
      <br>
      @Value("${myproperty}")<br>
      private String myproperty;<br>
      <br>
      I have the somewhat vague question: Are there any relation between
      the use case of these property annotations and the use case of
      string templates?<br>
      <br>
      The argument of the @Value annotation must be a String constant
      expression.<br>
      <br>
      Can a string template be used as a constant expression? Maybe if
      all its arguments are themselves are constants? Could a property
      syntax such as Spring's use string templates?<br>
      <br>
      Could code like the following do anything sensible?:<br>
      <br>
      @Value("\{someTemplateArg}")<br>
      private String someField;<br>
      <br>
      Maybe like this:<br>
      <br>
      @Value("\{MyProperties.SOME_PROPERTY_KEY}")<br>
      private String someField;<br>
      <br>
      Maybe there is no relation and the answer is simply "no". But
      maybe it worth to think about.<br>
      <br>
      I don't see constant expressions mentioned in the JEP:
      <a class="moz-txt-link-freetext" href="https://openjdk.org/jeps/430">https://openjdk.org/jeps/430</a><br>
      <br>
      Regards,<br>
      Jens Lideström<br>
      <br>
      PS: This feature in general seems very good to me.<br>
      <br>
    </div>
  </body>
</html>