RFR: 4987375: (reflect) Class.get{Declared}Method{s} does not return clone() for array type
Peter Levart
peter.levart at gmail.com
Wed Sep 4 15:30:37 UTC 2013
On 09/04/2013 03:55 PM, Joel Borggren-Franck wrote:
> Hi,
>
> Please review fix for: http://bugs.sun.com/view_bug.do?bug_id=4987375
>
> Webrev: http://cr.openjdk.java.net/~jfranck/4987375/webrev.01/
> Specdiff: http://cr.openjdk.java.net/~jfranck/4987375/specdiff/java/lang/Class.html
Hi Joel,
At getDeclaredMethods() the 2nd paragraph says:
"If this Class object represents a type that has multiple declared
methods with the same name and parameter types, but different return
types, then the returned array has a Method object for each such method."
I know that reflection operates on runtime class file format not on Java
source, but for an average Java programmer this statement is confusing.
(S)He might wonder how it is even possible to declare two methods with
same name and parameter types, but with different return type. Of
course, reflection also returns synthetic bridge methods that are not
declared in source but generated by javac. How to describe that fact in
javadoc if it only refers to JLS which doesn't know about these terms
(or barely mentions them not describing them in full)?
So what about the following in 1st paragraph:
"Returns an array containing |Method| objects reflecting all the
declared methods of the class or interface represented by this |Class|
object, including public, protected, default (package) access, and
private methods*. This includes br**idge methods generated by compiler
(see {@link #isBridge}),* but exclud*es* inherited methods."
And 2nd:
"If this Class object represents a type that has multiple declared
*(including bridge)* methods with the same name and parameter types, but
different return types, then the returned array has a Method object for
each such method."
...and a possible pointer to (java compiler specification?
http://docs.oracle.com/javase/tutorial/java/generics/bridgeMethods.html#bridgeMethods
?)
And similar with getMethods()...
Regards, Peter
>
> There are two issues here,
>
> - First a getInterfaces() call on an array Class instance does return
> Cloneable and Serializable. This is specified for
> getGenericInterfaces() but not specified in getInterface(). The fix is
> to update the spec to match the implementation, which also aligns it
> with getGenericInterfaces().
>
> - Also even though JLS states that array types have an implementation of
> clone() overriding the Object method, it is not included in
> get{Declared}Method{s}. Again the fix is to note this in the spec.
>
> Me and Alex have also worked on the structure of the docs trying to
> unify them and have a better flow. Rough outline is:
>
> <!-- Basic result -->
> <!-- Interesting results -->
> <!-- Empty results -->
> <!-- Order of results -->
>
> cheers
> /Joel
More information about the core-libs-dev
mailing list