[string-templates] Processors with side effects

Brian Goetz brian.goetz at oracle.com
Wed Sep 21 13:03:02 UTC 2022


> Hello!
>
> I was thinking about how Java beginners may benefit from string
> templates. Some teaching materials rely on System.out.printf to
> produce formatted output, like
>
> System.out.printf("Hello %s!", user);
>
> With string templates proposal, we can use
>
> System.out.println(FMT."Hello %s\{user}!");
>
> This is not very exciting. But I realised that PrintStream may
> implement TemplateProcessor by itself (returning Void or whatever),
> and print directly:
>
> System.out."Hello %s\{user}!";
>
> Will such use cases be encouraged, or this should be considered as
> misuse of the feature?

We anticipated that some libraries may want to implement 
TemplateProcessor in order to do this.  However, whether we do so for 
PrintStream will require thought.  The former version may not be 
exciting, but it is clear, and users will have no question what is going 
on.  The latter represents an opinionated "this is the formatter we will 
use for the next century", and is a choice to be taken carefully.  One 
of the great things about the current release cadence (plus preview 
mechanism) is that it is not necessary any more to do everything at 
once; we can let things sit for a while and see how they settle.




More information about the amber-spec-observers mailing list