RFR: 8267587: Update java.util to use enhanced switch [v5]
Tagir F.Valeev
tvaleev at openjdk.java.net
Wed May 26 02:22:43 UTC 2021
On Tue, 25 May 2021 15:51:38 GMT, Chris Hegarty <chegar at openjdk.org> wrote:
>> Tagir F. Valeev has updated the pull request incrementally with one additional commit since the last revision:
>>
>> More vertical alignment
>
> src/java.base/share/classes/java/util/Calendar.java line 1507:
>
>> 1505: }
>> 1506: case "japanese" -> cal = new JapaneseImperialCalendar(zone, locale, true);
>> 1507: default -> throw new IllegalArgumentException("unknown calendar type: " + type);
>
> In this case, it would be good to yield the result of the switch expression and assign that to a local, rather than assigning in each of the case arms, e.g:
>
> final Calendar cal = switch (type) {
> case "gregory" -> new GregorianCalendar(zone, locale, true);
> case "iso8601" -> {
> GregorianCalendar gcal = new GregorianCalendar(zone, locale, true);
> // make gcal a proleptic Gregorian
> gcal.setGregorianChange(new Date(Long.MIN_VALUE));
> // and week definition to be compatible with ISO 8601
> setWeekDefinition(MONDAY, 4);
> yield gcal;
> }
> case "buddhist" -> {
> var buddhistCalendar = new BuddhistCalendar(zone, locale);
> buddhistCalendar.clear();
> yield buddhistCalendar;
> }
> case "japanese" -> new JapaneseImperialCalendar(zone, locale, true);
> default -> throw new IllegalArgumentException("unknown calendar type: " + type);
> };
Done, thanks!
-------------
PR: https://git.openjdk.java.net/jdk/pull/4161
More information about the security-dev
mailing list