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

Patrick Concannon pconcannon at openjdk.java.net
Tue May 25 10:36:00 UTC 2021


On Tue, 25 May 2021 06:01:49 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:
> 
>   Indent some lines to make GitHub diff happier

src/java.base/share/classes/java/util/GregorianCalendar.java line 1730:

> 1728:         int value = -1;
> 1729:         switch (field) {
> 1730:             case MONTH -> {

HI @amaembo, thanks for taking a look at this.

I think you should be careful here, and ask is introducing the enchanced switch adding any value? While I think the enchanced switch can be valuable when it makes the code more readable, it shouldn't be introduced just for the sake of using it.

src/java.base/share/classes/java/util/PropertyPermission.java line 337:

> 335:      */
> 336:     static String getActions(int mask) {
> 337:         return switch (mask & (READ | WRITE)) {

Just a suggestion, but it might be more readable if you align the lambda operators

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

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


More information about the core-libs-dev mailing list