8282131: java.time.ZoneId should be a sealed abstract class

Reviewed-by: iris, rriggs, bpb, lancea, mchung, scolebourne
This commit is contained in:
Naoto Sato 2022-02-28 13:22:15 +00:00
parent c58f5c67d1
commit 0ae3d1d59c

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2012, 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2012, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -169,14 +169,14 @@ import static java.util.Map.entry;
* The {@code equals} method should be used for comparisons.
*
* @implSpec
* This abstract class has two implementations, both of which are immutable and thread-safe.
* One implementation models region-based IDs, the other is {@code ZoneOffset} modelling
* offset-based IDs. This difference is visible in serialization.
* This abstract sealed class permits two implementations, both of which are immutable and
* thread-safe. One implementation models region-based IDs, the other is {@code ZoneOffset}
* modelling offset-based IDs. This difference is visible in serialization.
*
* @since 1.8
*/
@jdk.internal.ValueBased
public abstract class ZoneId implements Serializable {
public abstract sealed class ZoneId implements Serializable permits ZoneOffset, ZoneRegion {
/**
* A map of zone overrides to enable the short time-zone names to be used.
@ -471,11 +471,7 @@ public abstract class ZoneId implements Serializable {
/**
* Constructor only accessible within the package.
*/
ZoneId() {
if (getClass() != ZoneOffset.class && getClass() != ZoneRegion.class) {
throw new AssertionError("Invalid subclass");
}
}
ZoneId() {}
//-----------------------------------------------------------------------
/**