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

java.time.ZoneId should be a sealed abstract class

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Fixed
    • Icon: P3 P3
    • 19
    • 19
    • core-libs
    • b12

      The impl spec of java.time.ZoneId states that ZoneId has two implementations:
          "One implementation models region-based IDs, the other is {@code ZoneOffset} modelling offset-based IDs."

      The ZoneId constructor has this check to ensure no other subclass can extend it:
          ZoneId() {
              if (getClass() != ZoneOffset.class && getClass() != ZoneRegion.class) {
                  throw new AssertionError("Invalid subclass");
              }
          }

      ZoneId can be made a sealed abstract class that permits ZoneOffset and ZoneRegion to extend. The test in the constructor would no longer be needed.

            naoto Naoto Sato
            mchung Mandy Chung
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Resolved: