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.
-Chris.
RĂ©mi