• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How To execute a function call

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
Iam doing a project to monitor the invocation of each package in a Java application. Iam sending each call to a function to my own method where I want to execute it. Iam passing the function call as a string to my function. I would like to know how will I be able to execute the string.
for example: if we have
System.out.println("Hello World"); in the original code. then Iam modifying the code as
mypackage.monitor("System.out.println("Hello World"); ");
where mypackage is the package containing the method monitor.
I would like to know how can I execute the command in monitor method and then go to the next line in the original source code.
Will anybody please help me.
-Parwez
 
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi
i think u r doing it wrong way.
u can't do it the way u r trying. because when u r passing the statement as an string it is getting compiled as a string. no way it can give u correct results. moreover u extract statement in the monitor method but its not compiled as a java statement, it can't run.
u can run operating system commands like that but once compiler has done its job and code is handed over to the interpretter it can't come back to compiler by itself just for 1 or 2 statements.
think some other way out for your application.
harish
 
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Looks like the Method class (java.lang.reflect, JDK 1.2.2) may be of some help, as would the java.lang.Class class. You would then have object references that you could pass to monitor() to have it execute the given Method in a given Class or something similar.
 
Aaaaaand ... we're on the march. Stylin. Get with it tiny ad.
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic