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

implement Sealed Classes as a standard feature in Java

    XMLWordPrintable

Details

    • CSR
    • Resolution: Approved
    • P3
    • 17
    • core-libs
    • None
    • behavioral
    • minimal
    • no change in behavior, the sealed classes feature is being made final
    • Java API, Language construct, Class file construct
    • SE

    Description

      Summary

      Sealed Classes were originally proposed by JEP 360 in 2019 and was targeted to JDK 15 as a preview feature. Feedback on the feature was positive. Some changes were proposed including the enhancement of narrowing reference conversion to perform stricter checking of cast conversions with respect to sealed type hierarchies. Sealed Classes were proposed again by JEP 397 and targeted to JDK 16, again as a preview feature. Feedback suggests that the Sealed Classes feature is now ready to be made final and permanent as proposed by JEP 409.

      Problem

      The preview status of Sealed Classes prevents usage in standard Java.

      Solution

      Remove the preview status requirement from Sealed Classes related APIs.

      Specification

      This CSR is concerned only with removing the preview status from the API. The changes are listed below.

      Note: apart from the changes to java.lang.Class related API a small change to the API of com.sun.source.tree.ClassTree is also included.

      diff --git a/src/java.base/share/classes/java/lang/Class.java b/src/java.base/share/classes/java/lang/Class.java
            *
            * @jls 8.1 Class Declarations
            * @jls 9.1 Interface Declarations
      -     * @since 15
      +     * @since 17
            */
      -    @jdk.internal.javac.PreviewFeature(feature=jdk.internal.javac.PreviewFeature.Feature.SEALED_CLASSES, reflective=true)
           @CallerSensitive
           public Class<?>[] getPermittedSubclasses() { ... }
      
            * subclasses; {@link #getPermittedSubclasses()} returns a non-null but
            * possibly empty value for a sealed class or interface.
            *
      -     * @return {@code true} if and only if this {@code Class} object represents a sealed class or interface.
      +     * @return {@code true} if and only if this {@code Class} object represents
      +     * a sealed class or interface.
            *
            * @jls 8.1 Class Declarations
            * @jls 9.1 Interface Declarations
      -     * @since 15
      +     * @since 17
            */
      -    @jdk.internal.javac.PreviewFeature(feature=jdk.internal.javac.PreviewFeature.Feature.SEALED_CLASSES, reflective=true)
      -    @SuppressWarnings("preview")
           public boolean isSealed() { ... }
      
      diff --git a/src/jdk.compiler/share/classes/com/sun/source/tree/ClassTree.java b/src/jdk.compiler/share/classes/com/sun/source/tree/ClassTree.java
      @@ -93,10 +93,8 @@ public interface ClassTree extends StatementTree {
            *
            * @return the subclasses
            *
      -     * @since 15
      +     * @since 17
            */
      -    @jdk.internal.javac.PreviewFeature(feature=jdk.internal.javac.PreviewFeature.Feature.SEALED_CLASSES,
      -                                       reflective=true)
           default List<? extends Tree> getPermitsClause() { ... }

      Attachments

        1. jep409-0414_b_2021.zip
          59 kB
        2. jep409-0414_C_2021.zip
          64 kB
        3. jep409-04142021.zip
          30 kB
        4. jep409-0420_D_2021.zip
          64 kB
        5. jep409-20120512.zip
          61 kB

        Issue Links

          Activity

            People

              vromero Vicente Arturo Romero Zaldivar
              gbierman Gavin Bierman
              Gavin Bierman
              Votes:
              0 Vote for this issue
              Watchers:
              7 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: