java - Why warning when trying to reflection on empty argument function -
i trying use reflection call funca()
of class clsa
. eclipse juno
showing warning in testa
class remark warning (a)
shown below.
the clsa
this:
public class clsa { string vara; ... ... private string funca() { return vara; } }
this code use reflection call on funca()
:
public class testa { public static void main(string[] args) { clsa clsa = new clsa(); class noparam[] = {}; method funca; string retstr; funca = clsa.class.getdeclaredmethod("funca", noparam); funca.setaccessible(true); retstr = (string) funca.invoke(clsa, null); // warning (a) } }
and warning get. don't understand message warning trying bring? how explicitly cast null
?
the argument of type null should explicitly cast object[] invocation of varargs method invoke(object, object...) type method. alternatively cast object varargs invocation
there can 2 types of method invocation, 1 call fixed argument, other call variable arguments.
if providing null argument, not clear java whether method variable parameters or no parameter @ (as variable parameters may accept no agrument).
so asks mention explicitly (object[])null or (object)null, if don't want provide argument.
Comments
Post a Comment