JAVADOC clarification needed in Class.getMethod
Kyung Koo Yoon
yoonforh at gmail.com
Sat Aug 29 13:44:58 UTC 2015
> 2015. 8. 29., 오후 10:40, Kyung Koo Yoon <yoonforh at gmail.com> 작성:
>
> Hi, Jochen.
>
> --
> --------------------
> Software Innovation Driver yoonforh at gmail dot com
> Analyze, Reason, Reshape the Question
> PGP http://www.javadom.com/personal/yoonforhatgmaildotcom.asc <http://www.javadom.com/personal/yoonforhatgmaildotcom.asc>
>> 2015. 8. 29., 오후 10:01, Jochen Theodorou <blackdrag at gmx.org <mailto:blackdrag at gmx.org>> 작성:
>>
>> Am 29.08.2015 10:56, schrieb Kyung Koo Yoon:
>>> Hi, all.
>>>
>>> The javadoc comment of java.lang.Class.getMethod API has following clause.
>>>
>>> @CallerSensitive
>>> public Method getMethod(String name, Class<?>... parameterTypes)
>>> throws NoSuchMethodException, SecurityException
>>>
>>>
>>> "The {@code parameterTypes} parameter is an array of {@code Class}
>>> objects that identify the method's formal parameter types, in declared
>>> order. If {@code parameterTypes} is {@code null}, it is
>>> treated as if it were an empty array."
>>>
>>> As you know the method signature changed to use varargs since JDK 1.5,
>>> if parameterTypes is given null, the compiler will interpret the parameter with “new Class[] { null }”.
>>
>> you are making a wrong assumption here. If null is given there will be
>> no wrapping in an array. varargs are defined that there is no wrapping
>> if the given argument type is compatible. For Class[] this is Class[]
>> and of course null. Even if you had been right, you could still give
>> produce a call with null by reflection or using the MethodHandles API
>
> You can check by simply decompiling the generated byte codes.
> vararg is not a JVM feature so the compiler pre-processes and the compiler handles the given null as array’s first element.
>
> Originally class.getMethod(“methodName”, null) should have meant a static method, but with vararg, it’s not.
Sorry, static is not correct. should have meant a void method.
>
>>
>> bye blackdrag
>>
>> --
>> Jochen "blackdrag" Theodorou
>> blog: http://blackdragsview.blogspot.com/ <http://blackdragsview.blogspot.com/>
More information about the core-libs-dev
mailing list