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

Class.getCanonicalName spec should explicitly cover array classes

XMLWordPrintable

    • Icon: CSR CSR
    • Resolution: Approved
    • Icon: P4 P4
    • 19
    • core-libs
    • None
    • behavioral
    • minimal
    • Describing existing behavior.
    • Java API
    • SE

      Summary

      Update the specification of Class.getCanonicalName method to explicitly describe the behavior for arrays.

      Problem

      Unlike other Class -> name methods in java.lang.Class, Class.getCanonicalName does not describe how arrays are handled.

      Solution

      Add explicit discussion of arrays (and primitive types, for good measure).

      Specification

      --- a/src/java.base/share/classes/java/lang/Class.java
      +++ b/src/java.base/share/classes/java/lang/Class.java
      @@ -1732,8 +1732,18 @@ public final class Class<T> implements java.io.Serializable,
            * <li>an array whose component type does not have a canonical name</li>
            * </ul>
            *
      +     * The canonical name for a primitive class is the keyword for the
      +     * corresponding primitive type ({@code byte}, {@code short},
      +     * {@code char}, {@code int}, and so on).
      +     *
      +     * <p>An array type has a canonical name if and only if its
      +     * component type has a canonical name. When an array type has a
      +     * canonical name, it is equal to the canonical name of the
      +     * component type followed by "{@code []}".
      +     *
            * @return the canonical name of the underlying class if it exists, and
            * {@code null} otherwise.
      +     * @jls 6.7 Fully Qualified Names and Canonical Names
            * @since 1.5
            */
           public String getCanonicalName() {

            darcy Joe Darcy
            darcy Joe Darcy
            Mandy Chung (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: