A variable way to call methods within an object
in
Programming Questions
•
19 days ago
Hi. I'm writing a program in which I have a ArrayList containing several objects. I want to have the ability to make calls to any of the objects. I think what I need is some sort of pathway or ID that I can store in a variable, Like so
- class Object {
- int number = 5;
- //just an example, so this won't be a proper class.
- void action() {
- }
- }
- ArrayList<Object> //for the sake of space, let's just pretend I've put 5 Objects in this:
- //sue, joe, bob, steve, and sirRodricTheThird.
- //dataType will need to be whatever data type I'll end up needing
- dataType idenify; //I need some sort of path or ID that links to those Objects, so that I can:
- identify = sue; //or however I'd need to do this (I DON'T want to copy the object sue over to identify. identify should hold a path to or ID that can be used to find sue.
- identify.action();
- identify = sirRodricTheThird;
- identify.number = 45;
- //you get the idea.
1