RFR: 8267670: Update java.io, java.math, and java.text to use switch expressions

Naoto Sato naoto at openjdk.java.net
Tue May 25 12:47:11 UTC 2021


On Tue, 25 May 2021 09:37:58 GMT, Patrick Concannon <pconcannon at openjdk.org> wrote:

> Hi,
> 
> Could someone please review my code for updating the code in the `java.io`, `java.math`, and `java.text` packages to make use of the switch expressions?
> 
> Kind regards,
> Patrick

src/java.base/share/classes/java/text/BreakIterator.java line 569:

> 567:             case SENTENCE_INDEX  -> breakIteratorProvider.getSentenceInstance(locale);
> 568:             default              -> null;
> 569:         };

No need to use the local variable `iterator` here. Simply return with the switch expression.

src/java.base/share/classes/java/text/NumberFormat.java line 982:

> 980:             case COMPACTSTYLE  -> provider.getCompactNumberInstance(locale, formatStyle);
> 981:             default            -> null;
> 982:         };

Same as `BreakIterator`. No need for `numberFormat`.

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

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


More information about the core-libs-dev mailing list