[PROPOSAL][JDK10] Introduce Executable.getParameterType(index)

Christoph Dreis christoph.dreis at freenet.de
Fri Oct 20 11:45:50 UTC 2017


Hey,

while discussing JDK-8029019 & JDK-8189266 Claes came up with the idea to
introduce non-copying access to the underlying parameter types of an
Executable [1]. While there is a (for a good reason?) package-private
Method.getSharedParameterTypes() already I thought of an alternative that
doesn't open up the parameterTypes array to the outside world and actually
solves the use-case where we wanted an allocation-free alternative for
Method.getParameterTypes()[index].

Here is a draft of what I'm thinking of:

Executable:
    /**
     * Returns the {@code Class} object that represents the formal
     * parameter type, at the given index, of the executable
     * represented by this object. The given index starts at 0 and
     * represents the declaration order of the parameters.
     *
     *
     * @param index index to look for the parameter type
     * @return the parameter type at the given index for the executable this
object
     * represents
     * @throws IndexOutOfBoundsException if the parameter type
     *      at the given index of the underlying executable could not be
found
     */
    public abstract Class<?> getParameterType(int index);

Method & Constructor:
   /**
     * {@inheritDoc}
     * @throws IndexOutOfBoundsException {@inheritDoc}
     * @since 18.3
     */
    public Class<?> getParameterType(int index) {
        if (index < 0 || index > getParameterCount()) {
            throw new IndexOutOfBoundsException("No parameter found on index
" + index);
        }
        return parameterTypes[index];
    }

As I don't know what the official @since should look like in the future, do
not pay too much attention on that. I'm not happy with the documentation
wording though.

What do you think about that? Is someone willing to sponsor this given it's
considered worthwhile.

Cheers,
Christoph

[1]
http://mail.openjdk.java.net/pipermail/core-libs-dev/2017-October/049520.htm
l



More information about the core-libs-dev mailing list