Revisit the String template syntax

Cay Horstmann cay.horstmann at gmail.com
Sat Apr 15 09:16:05 UTC 2023


On 15/04/2023 10.28, forax at univ-mlv.fr wrote:

> The real question is more, do we want two syntax for conceptually the same thing or not ?
> 
> Here is an example with an annotation,
> 
>    @Bean
>    class SpringBean {
> 
>        @Value("${myproperty}")
>        private String myproperty;
> 
>        public void foo() {
>            System.out.println(STR."myproperty: ${myproperty}");
>        }
>    }
> 
> 
I had to remind myself at https://www.baeldung.com/spring-value-annotation what @Value does. There is an ad-hoc syntax with ${key} and ${key: default} and #{...}. This is undoubtedly useful and clever, but it's the Spring useful-and-clever way.

To me, the distinction between \{} and ${} (and friends such as #{}) is meaningful. The former is a standard Java mechanism. The latter are handled by some library, and the only way to find out what they do is to consult the library documentation.

Cheers,

Cay

--

Cay S. Horstmann | http://horstmann.com | mailto:cay at horstmann.com


More information about the amber-spec-observers mailing list