<i18n dev> RFR: 8269124: Update java.time to use switch expressions (part II)
Aleksei Efimov
aefimov at openjdk.java.net
Tue Jun 22 15:44:29 UTC 2021
On Tue, 22 Jun 2021 10:50:17 GMT, Patrick Concannon <pconcannon at openjdk.org> wrote:
> Hi,
>
> Could someone please review the second half of my update for the `java.time` package to make use of switch expressions?
>
> This PR was split into two parts due to the large number of files affected.
>
> Kind regards,
>
> Patrick
Changes requested by aefimov (Committer).
src/java.base/share/classes/java/time/Instant.java line 852:
> 850: public Instant plus(long amountToAdd, TemporalUnit unit) {
> 851: if (unit instanceof ChronoUnit) {
> 852: switch ((ChronoUnit) unit) {
It looks like we need to put `return` here, otherwise `UnsupportedTemporalTypeException` will be thrown every time the method is called:
jshell> Instant.now()
$2 ==> 2021-06-22T15:35:28.771128667Z
jshell> $2.plus(10L, ChronoUnit.SECONDS)
| Exception java.time.temporal.UnsupportedTemporalTypeException: Unsupported unit: Seconds
| at Instant.plus (Instant.java:862)
| at (#5:1)
src/java.base/share/classes/java/time/ZonedDateTime.java line 1311:
> 1309: }
> 1310: default -> resolveLocal(dateTime.with(field, newValue));
> 1311: };
It looks like that the closing braces `}` is missing here.
-------------
PR: https://git.openjdk.java.net/jdk/pull/4552
More information about the i18n-dev
mailing list