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

Popular posts from this blog

image - ClassNotFoundException when add a prebuilt apk into system.img in android -

I need to import mysql 5.1 to 5.5? -

Java, Hibernate, MySQL - store UTC date-time -