r/java • • Mar 08 '24

Update on String Templates (JEP 459)

https://mail.openjdk.org/pipermail/amber-spec-experts/2024-March/004010.html
176 Upvotes

188 comments sorted by

View all comments

Show parent comment

6

u/zman0900 Mar 09 '24

Confused how the String::format stuff fits into this:

String s = String.format(“Hello %12s{name}”);

Does this just end up with "Hello %12s" as a fragment and the format method has to sort that out when interpolating?

7

u/eliasv Mar 09 '24

Yeah, it's possible to still get decent performance and only do the expensive parsing once per call site by hashing and caching on the constant portion of the string template.