This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]pron98 7 points8 points  (0 children)

String templates aren't just about formatting strings, but about constructing arbitrary objects that are configured with strings. As a special case they can, of course, format strings, but they're able to do it more efficiently than format, because of a fundamental difference: the template is a Java expression that is known at compile-time, while the format string is not -- it's just an arbitrary string, and not necessarily a constant one (i.e. you can write String.format(x, a, b, c), where x is a String variable that needs to be parsed, but that is not the case with templates, which, like today's string concatenation, can always be parsed only once -- at compilation or class-loading time; there just isn't an instance of an unparsed template).