Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8282375

java.time.ZoneId should be a sealed abstract class

XMLWordPrintable

    • Icon: CSR CSR
    • Resolution: Approved
    • Icon: P3 P3
    • 19
    • core-libs
    • None
    • minimal
    • It has already been an implementation specification. Changing it with a better construct will not cause any compatibility issues.
    • Java API
    • SE

      Summary

      Change java.time.ZoneId to a sealed abstract class.

      Problem

      This is a refactoring of the said class with a better construct, as the class' implementation specification has already been limiting the subclassing to two subclasses, i.e., ZoneOffset and ZoneRegion.

      Solution

      Add sealed modifier to the class declaration, and permit ZoneOffset and ZoneRegion as the subclasses.

      Specification

      Change the declaration of the class from:

      public abstract class ZoneId implements Serializable

      to:

      public abstract sealed class ZoneId implements Serializable permits ZoneOffset, ZoneRegion

      Change the @implSpec in the class description to:

       * @implSpec
       * 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.

            naoto Naoto Sato
            mchung Mandy Chung (Inactive)
            Iris Clark, Lance Andersen, Mandy Chung (Inactive), Roger Riggs
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: