<i18n dev> RFR: 8282819: Deprecate Locale class constructors [v3]
Naoto Sato
naoto at openjdk.java.net
Mon Mar 28 16:02:52 UTC 2022
On Sun, 27 Mar 2022 08:45:01 GMT, ExE Boss <duke at openjdk.java.net> wrote:
>> Naoto Sato has updated the pull request incrementally with one additional commit since the last revision:
>>
>> Fixed a build failure
>
> src/java.base/share/classes/java/util/Locale.java line 819:
>
>> 817: * @since 19
>> 818: */
>> 819: public static Locale of(String... fields) {
>
> Arguably, there should be `Locale.of` overloads taking 0 to 4 arguments, so that it’s not necessary to box the fields in a `String` array.
While it is true for completeness, I would limit the addition of new method as little as possible, because there are already several ways to obtain a Locale object.
> src/java.base/share/classes/java/util/Locale.java line 825:
>
>> 823: case 2 -> getInstance(fields[0], "", fields[1], "", null);
>> 824: case 3 -> getInstance(fields[0], "", fields[1], fields[2], null);
>> 825: default -> getInstance(fields[0], fields[3], fields[1], fields[2], null);
>
> This should probably throw `IllegalArgumentException` when more than 4 fields are passed:
> Suggestion:
>
> case 4 -> getInstance(fields[0], fields[3], fields[1], fields[2], null);
> default -> throw new IllegalArgumentException(/* TODO: message */);
Thanks for the suggestion. Will incorporate the exception in the spec/impl.
-------------
PR: https://git.openjdk.java.net/jdk/pull/7947
More information about the i18n-dev
mailing list