RFR - JDK-8203444 String::formatted (Preview)

Florian Weimer fweimer at redhat.com
Tue May 21 14:42:57 UTC 2019

* Jim Laskey:

> Please do a code review of the new String::formatted instance method. This method was originally introduced under the name "format"
> in conjunction with Raw String Literals. The method is being reintroduced in conjunction with Text Blocks and renamed to avoid method
> resolution conflicts against the static method String::format.
> Example of use:
>     String name = "Smith, Pat";
>     String address = "123 Maple St., Anytown, Anywhere";
>     String phone = "999-555-1234";
>     String client = """
>                     Name: %s
>     Address: %s
>     Phone: %s
>                     """.formatted(name, address, phone); 

I'm a bit concerned by the ambiguity between the version with and
without the Locale argument.  Not sure if this is the kind of feedback
you are looking for.

(String::format does not have this ambiguity and had been able to avoid
it easily, so it's not a good guide here.)


More information about the compiler-dev mailing list