RFR - JDK-8203444 String::formatted (Preview)
Jim Laskey
james.laskey at oracle.com
Tue May 21 16:30:10 UTC 2019
I suppose String::formattedLocalized(Locale lc, Object... args) would also be reasonable.
> On May 21, 2019, at 12:56 PM, Jim Laskey <james.laskey at oracle.com> wrote:
>
> 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)".
>
> Correct?
>
> -- Jim
>
>
>
>
>> 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.
>>>
>>> Example:
>>>
>>> "%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, """
>> %s
>> """, Locale.JAPAN);
>>
>> Then perhaps we wouldn't need the formatted method which takes a Locale
>> object.
>>
>> Thanks,
>> Florian
>
More information about the core-libs-dev
mailing list