Given this is a spec issue, I think it should be discussed on the spec-experts 
list, 

> From: "Brian Goetz" <[email protected]>
> To: "Bas Leijdekkers" <[email protected]>, "amber-dev"
> <[email protected]>
> Sent: Friday, September 15, 2023 5:17:53 PM
> Subject: Re: String Templates Expression Statement

> 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.
A string template is a value, it does not produce anything. So I suppose you 
mean a String template "processor" is supposed to produce something. 

And for the record, the reason we are giong back and forth is that restricting 
the syntax to only support expression does not fit well with the fact that a 
processor is specified as an interface. 
So we are allowing the definition of a processor to have states but we are 
disallowing the syntax that calls a processor to modify those states. 

Personnally, I can leave with that, the Java semantics is full of this kind of 
special cases. 

And if someone really want a processor to acts as builder in the generic sense, 
the syntax 
var _ = processor."..."; 

works anyway. 

Rémi 

> 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

Reply via email to