memory - Java How to invoke any method -


i'm writing program tak measure method memory consumtion. through program user can choose jar file jar file user can choose class jar , class can choose method , program should give method memory consumption.

problem user can choose method , don't know how give method proper parameters. use reflection ofcourse , method invoke().

i found post: java reflection how invoke method unknown number of arguments?

in post helpfull part of code:

class iclass; method method;     // parameters , set values. class<?>[] methodparameters = method.getparametertypes();  object[] parametersobjects = new object[methodparameters.length];  (int x = 0; x < methodparameters.length; x++)      parametersobjects[x] = methodparameters[x].newinstance();   // invoking method. object value = method.invoke(iclass, parametersobjects); 

it works specific cases ofted classcastexception or illegalargumentexception.

my question is: there way in better way invoke method examples parameters? or maybe generate them in other way ?


Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -