On 27 Dec 2012, at 22:26, Remi Forax <fo...@univ-mlv.fr> wrote:

> On 12/27/2012 10:41 PM, Chris Hegarty wrote:
>> 
>>>> Method method = clazz.getMethod(DOM_LEVEL3_METHOD);
>>>> is equivalent to
>>>> Method method = clazz.getMethod(DOM_LEVEL3_METHOD, new Class<?>[0]);
>>>> so you allocate an empty array each time you call getMethod.
>>>> 
>>>> A better patch is to cast null to Class<?>[] (or Object[] for invoke)
>>>> Method method = clazz.getMethod(DOM_LEVEL3_METHOD, (Class<?>[])null);
>> 
>> Is this something that the compiler could do? Or is this "inefficiency" 
>> baked into spec, or serve another purpose?
> 
> The compiler has to create an empty array if there is not enough parameter 
> from the spec (JLS7 15.12.2.4), but Class.getMethod() or Method.invoke() are 
> special because they specified that null is a valid argument equivalent to an 
> empty array.

Ok, thanks Remi.

-Chris.

> 
>> 
>> -Chris.
> 
> Rémi
> 

Reply via email to