8265746: Update java.time to use instanceof pattern variable (part II)

Reviewed-by: dfuchs, lancea, rriggs, chegar, naoto
This commit is contained in:
Patrick Concannon 2021-04-26 08:32:20 +00:00
parent a85f6cbbaa
commit 45c5da0fd3
20 changed files with 104 additions and 152 deletions

View file

@ -682,10 +682,9 @@ public final class YearMonth
*/
@Override
public YearMonth with(TemporalField field, long newValue) {
if (field instanceof ChronoField) {
ChronoField f = (ChronoField) field;
f.checkValidValue(newValue);
switch (f) {
if (field instanceof ChronoField chronoField) {
chronoField.checkValidValue(newValue);
switch (chronoField) {
case MONTH_OF_YEAR: return withMonth((int) newValue);
case PROLEPTIC_MONTH: return plusMonths(newValue - getProlepticMonth());
case YEAR_OF_ERA: return withYear((int) (year < 1 ? 1 - newValue : newValue));