I’m working in a simulation environment called AnyLogic and it uses Java as its underlying code.
In my example, the user draws a flowchart and at runtime each element of the flowchart is instantiated. I can determine what the user has draw by the code:
LinkedList eo = (LinkedList) this.getEmbeddedObjects();
- which returns a list of Strings representing the names of all the objects in the flowchart.
I would like to dynamically access these objects’ methods but I’m new to Java and not sure how to go about this. From what I understand of reflection I can instantiate a classForName, but in this case I already have instantiated objects and I want to use the Strings to access them.
I am unsure how to proceed and appreciate any suggestions.
Thanks 🙂
You can use Java reflection API for the task.
This API is somewhat verbose though. If that’s an issue, then you should go for one of the available fluent reflection APIs.