String Templates Expression Statement

Brian Goetz brian.goetz at oracle.com
Fri Sep 15 15:17:53 UTC 2023


We have gone back and forth on this, but I believe we are better served 
by not allowing string templates as statement expressions.  A string 
template is supposed to _produce something_, not _operate by side 
effects_. A statement expression serves only to normalize its use to 
produce side effects.

On 7/12/2023 7:26 AM, Bas Leijdekkers wrote:
> Hello Amber-dev,
>
> In the String Templates draft specification, I don't see any changes 
> in JLS Chapter 14.8 Expression Statements. This makes me think that 
> Template Expressions are not allowed to be used as statements. However 
> javac in jdk21-ea accepts a Template Expression used as a statement 
> without reporting any error. (I am using build 21-ea+30-2426). So it 
> appears to me either the specification or javac is incorrect. Which 
> one should I believe?
>
> Example code:
> ```
> class TemplateExpressionStatement {
>     public static void main(String[] args) {
>         STR."\{}";
>     }
> }
> ```
>
> Bas
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/amber-dev/attachments/20230915/2c2c7d1a/attachment-0001.htm>


More information about the amber-dev mailing list