RFR: 8267587: Update java.util to use enhanced switch [v5]

Brian Goetz briangoetz at openjdk.java.net
Tue May 25 16:55:06 UTC 2021


On Tue, 25 May 2021 11:49:18 GMT, Tagir F. Valeev <tvaleev at openjdk.org> wrote:

>> Inspired by PR#4088. Most of the changes are done automatically using IntelliJ IDEA refactoring. Some manual adjustments are also performed, including indentations, moving comments, extracting common cast out of switch expression branches, etc.
>> 
>> I also noticed that there are some switches having one branch only in JapaneseImperialCalendar.java. Probably it would be better to replace them with `if` statement?
>
> 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/JapaneseImperialCalendar.java line 1124:

> 1122:                 return Math.max(LEAST_MAX_VALUES[YEAR], d.getYear());
> 1123:             }
> 1124:         }

A switch with one element here is kind of weird.  I would turn this into "return switch (field) { ... }", with two cases, YEAR and default.

src/java.base/share/classes/java/util/JapaneseImperialCalendar.java line 1371:

> 1369:                     }
> 1370:                 }
> 1371:             }

Pull value assignment out of switch?

-------------

PR: https://git.openjdk.java.net/jdk/pull/4161


More information about the core-libs-dev mailing list