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

Including sealing information Class.toGenericString()

    XMLWordPrintable

Details

    • CSR
    • Resolution: Approved
    • P4
    • 23
    • core-libs
    • None
    • behavioral
    • minimal
    • Relying on exact textual output of toString-like methods is brittle.
    • Java API
    • SE

    Description

      Summary

      Include sealed/non-sealed conceptual modifiers in the output of Class.toGenericString().

      Problem

      While appearing as a modifier in Java source, neither sealed nor non-sealed is not included in the output of Class.toGenericString(), which tends to include more information than Class.toString().

      Solution

      Update the specification and implementation of Class.toGenericString() to include sealed/non-sealed information for a class or interface.

      Consistent with omitted implements and extends information, the list of permitted classes/interfaces is omitted by Class.toGenericString().

      Specification

      --- a/src/java.base/share/classes/java/lang/Class.java
      +++ b/src/java.base/share/classes/java/lang/Class.java
      @@ -261,7 +261,8 @@ public String toString() {
      
           /**
            * Returns a string describing this {@code Class}, including
      -     * information about modifiers and type parameters.
      +     * information about modifiers, {@link #isSealed() sealed}/{@code
      +     * non-sealed} status, and type parameters.
            *
            * The string is formatted as a list of type modifiers, if any,
            * followed by the kind of type (empty string for primitive types

      Attachments

        Issue Links

          Activity

            People

              darcy Joe Darcy
              darcy Joe Darcy
              Pavel Rappo
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: