Draft Spec for Second Preview of String Templates (JEP 459)

Remi Forax forax at univ-mlv.fr
Tue Oct 10 06:38:53 UTC 2023


----- Original Message -----
> From: "Tagir Valeev" <amaembo at gmail.com>
> To: "Gavin Bierman" <gavin.bierman at oracle.com>
> Cc: "amber-spec-experts" <amber-spec-experts at openjdk.java.net>
> Sent: Tuesday, October 10, 2023 7:33:13 AM
> Subject: Re: Draft Spec for Second Preview of String Templates (JEP 459)

> Hello, experts!
> 
> Probably it's possible to fix the small thing I wrote before? Namely,
> the type of template expression and its thrown exceptions are
> determined by the template expression class signature (namely, the
> instantiation of R and E generic parameters of Processor) and ignoring
> the actual signature of the process() method, which may have covariant
> return type and thrown exception type declared. This looks out of sync
> with the rest of Java. Example:
> 
> public final class TemplateTest {
>    interface AnyProcessor extends StringTemplate.Processor<Object,
> Throwable> {}
> 
>    static class IntProcessor implements AnyProcessor {
>       @Override
>       public Integer process(StringTemplate stringTemplate) {
>          return 123;
>       }
>    }
> 
>    public static void main(String[] args) {
>       // error: incompatible types: java.lang.Object cannot be
> converted to java.lang.Integer
>       Integer xyz = new IntProcessor()."hello";
>       // error: unreported exception java.lang.Throwable; must be
> caught or declared to be thrown
>       Object xyz2 = new IntProcessor()."hello";
>    }
> }
> 
> I'm not sure whether current behavior is explicitly stated in the spec
> draft, but the reference implementation behaves this way. I would
> expect this code to be compilable.
> 
> Note that we have a similar implicit method invocation construct,
> try-with-resources, and it respects the actual signature of the
> close() method (namely, declared exceptions). I think that similarly
> we should respect the actual method signature here.

The enhanced for-loop also uses the precise iterator type not java.util.Iterator.

I agree with Tagir, they should all work the same way. 

> 
> With best regards,
> Tagir Valeev.

regards,
Rémi

> 
> On Mon, Oct 9, 2023 at 4:46 PM Gavin Bierman <gavin.bierman at oracle.com> wrote:
>>
>> Dear experts:
>>
>> The first draft of a spec covering JEP 459 (String Templates (Second Preview))
>> is now available at:
>>
>> https://cr.openjdk.java.net/~gbierman/jep459/latest
>>
>> Feel free to contact me directly or on this list with any comments.
>>
>> Thanks
>> Gavin
>>
>>
>> > On 5 Oct 2023, at 13:20, Mark Reinhold <mark.reinhold at oracle.com> wrote:
>> >
>> > https://openjdk.org/jeps/459
>> >
>> > Summary: Enhance the Java programming language with string
>> > templates. String templates complement Java's existing string literals
>> > and text blocks by coupling literal text with embedded expressions and
>> > template processors to produce specialized results. This is a preview
>> > language feature and API.
>> >
> > > - Mark


More information about the amber-spec-experts mailing list