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

Clarify Class.getDeclaredConstructor specification

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P4 P4
    • 19
    • 19
    • core-libs
    • b03

           * Returns a {@code Constructor} object that reflects the specified
           * constructor of the class or interface represented by this
           * {@code Class} object...

      _or interface_ does not make any sense, since an interface never has a constructor.


      More broadly, the spec of `getDeclaredConstructor` (and `getConstructor`) is inadequate because it does not specify what happens if the `Class` object represents a non-class entity. It would be appropriate to clarify the `@throws` of `getDeclaredConstructor` (and `getConstructor`) as follows:

          NoSuchMethodException - if a matching method is not found***, or if this `Class` object represents an interface, a primitive type, an array class, or void`.***


      Separately, the spec of `getConstructors` can be improved by wording it consistently with `getDeclaredConstructors`:

      Old: "An array of length 0 is returned if the class has no public constructors, or ***if the class is an array class, or if the class reflects a primitive type or void***." (The starred text is wrong because a class never reflects a primitive type or void -- doing such reflection is the job of a `Class` object, a `Field` object, a `Method` object, etc -- please search the spec of java.lang.Class for "reflects" and observe that this is the only place which says a class reflects anything.)

      New: "An array of length 0 is returned if the class has no public constructors, or ***if this `Class` object represents an interface, a primitive type, an array class, or void.***"

            darcy Joe Darcy
            prappo Pavel Rappo (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: