JDK-8281767 : Update java.lang.reflect.Parameter to implement Member
  • Type: CSR
  • Component: core-libs
  • Sub-Component: java.lang:reflect
  • Priority: P4
  • Status: Draft
  • Resolution: Unresolved
  • Fix Versions: 19
  • Submitted: 2022-02-15
  • Updated: 2022-02-15
Related Reports
CSR :  
Description
Summary
-------

Retrofit `java.lang.reflect.Parameter` to implement `java.lang.reflect.Member`.

Problem
-------

Unnecessarily board least-common supertype of `Parameter` and similar reflection modeling classes.

Solution
--------

Retrofit `java.lang.reflect.Parameter` to implement `java.lang.reflect.Member`, adding an implementing of the one missing method.

Specification
-------------

    diff --git a/src/java.base/share/classes/java/lang/reflect/Parameter.java b/src/java.base/share/classes/java/lang/r
    eflect/Parameter.java
    index 780319585ab..7e7f7dd59f6 100644
    --- a/src/java.base/share/classes/java/lang/reflect/Parameter.java
    +++ b/src/java.base/share/classes/java/lang/reflect/Parameter.java
    @@ -27,6 +27,7 @@ package java.lang.reflect;
     import java.lang.annotation.*;
     import java.util.HashMap;
     import java.util.Map;
    +import java.util.Set;
     import java.util.Objects;
     import sun.reflect.annotation.AnnotationSupport;
     
    @@ -39,7 +40,7 @@ import sun.reflect.annotation.AnnotationSupport;
      *
      * @since 1.8
      */
    -public final class Parameter implements AnnotatedElement {
    +public final class Parameter implements AnnotatedElement, Member {
     
         private final String name;
         private final int modifiers;
    @@ -148,6 +149,19 @@ public final class Parameter implements AnnotatedElement {
             return executable;
         }
     
    +    /**
    +     * {@return the class object of the {@code Executable} declaring
    +     * this parameter}
    +     * @implSpec
    +     * The returned value is equal to {@code
    +     * getDeclaringExecutable().getDeclaringClass()}.
    +     * @since 19
    +     */
    +    @Override
    +    public Class<?> getDeclaringClass() {
    +        return executable.getDeclaringClass();
    +    }
    +
         /**
          * {@return the Java language {@linkplain Modifier modifiers} for
          * the parameter represented by this object}



Comments
But a parameter is NOT a Member of a Class! public interface Member Member is an interface that reflects identifying information about a single member (a field or a method) or a constructor.
15-02-2022