Reflection: take values from an unknown running alpplication
- by Dr.Lesh
I'm writing an application that searchs for Semaphore types in the fields of unknown classes in unknown application (passed by user). I made it using Reflection and it worked.
Now I want to fill up these semaphores with values, taking them from a running instance of this unknown application. So i took the class with "main" method of this unknown application, made a newInstance, and passed it when invoking the main method to start the application:
Class mainClass = getItSomeWhere();
Object instance = mainClass.newInstance();
Method mainMethod = mainClass.getDeclaredMethod("main", new Class[]{String[].class});
mainMethod.invoke(instance, new Object[]{args});
and it worked fine.
Now, how can I get the semaphore values, taking them from the classes of this running application, when I only have an instance of the main class?
Many thanks for the answers.