java - Trick the reflector -
there piece of java code did not write , can't change uses reflector call class' method. (i haven't seen code):
.... params[0] = something; .... class c = class.forname(name); method m = c.getdeclaredmethod(methodname, pt); if (modifier.isstatic(m.getmodifiers())) { res = m.invoke(null, params); } else { obj = c.newinstance(); res = m.invoke(obj, params); } ....
so far good.
i control class' name, method's name , parameters. can send combination of those, there catch though: first parameter hard-coded, parameter send appended params array. method has accept parameter.
my question is: there way create type , use in there? this:
public class printwrapper { public static void println(somethingtype something, string arg) { system.out.println(arg); } }
i tried using class name, didn't work, idea? need sort of anonymous class or something.
and no, can't change source code or add class system. things control class' name, method's name , rest of parameters.
the things control class' name, method's name , rest of parameters.
then answer:
there no way create type , use in there?
Comments
Post a Comment