RFR - JDK-8203444 String::formatted (Preview)
james.laskey at oracle.com
Tue May 21 15:56:11 UTC 2019
Good point. To make sure I fully understand what you are stating,
- The argument for having an instance method is reasonable to achieve "flowiness".
- However, only one version is necessary or desired, that is, "public String formatted(Object... args)".
- In cases where Locale needs to be overridden, then either use "String.format(Locale lc, String fmt, Object... args)" or globally set "Locale.setDefault(Locale lc)".
> On May 21, 2019, at 12:44 PM, Florian Weimer <fweimer at redhat.com> wrote:
> * Jim Laskey:
>> All discussion is valid. I agree the ambiguity is tricky, but can be
>> resolved by using explicit locale.
>> "%s".formatted(Locale.getDefault(), Locale.JAPAN);
>> This guarantees the "public String formatted(Locale l,
>> Object... args)" form is chosen with the second Locale as an argument.
> There is also the cognitive overhead. I think the key question is
> whether this is so bad:
> String.format(Locale.US, """
> """, Locale.JAPAN);
> Then perhaps we wouldn't need the formatted method which takes a Locale
More information about the core-libs-dev