java - Meaning of new Class[0] in Reflection API -
i came across statement:
o1 = o1.getclass().getmethod(getter, new class[0]).invoke(o1, new object[0]);
can please tell me new class[0]
, new object[0]
in case, o1
object
?
getmethod() takes list of types arguments. passing zero-length array means has no arguments. same invoke().
from documentation class.getmethod
:
if parametertypes null, treated if empty array.
from documentation method.invoke
:
if number of formal parameters required underlying method 0, supplied args array may of length 0 or null.
the line posted, in context, then, equivalent to:
o1 = o1.getclass().getmethod(getter, null).invoke(o1, null);
personally find use of null
there more readable (although use of zero-length array have benefit of self-documenting type of parameter programmer not passing, if means you).
Comments
Post a Comment