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.
Basicly, I need to be able to call methods from the objects without depending on their location within the ArrayList, as that won't be staying constant at all. Also, it needs to be possible that other objects can do this. I honestly have no clue what it is I'd need. Any ideas?
I'm stuck on a program I'm writing. Here's what I need: I have class Base, and four subclasses of that class called Base1, Base2, ect. I need a ArrayList for each of the subclasses, but I need to be able to make calls to objects inside them. I think an Base[] array that holds the four ArrayLists may work. Sorry about how loose this is, I can get a code example up in a day or two.
In a program I am writing, I want to loop through several object functions and use the results. To make it simple, I want to have an array that contains the function calls, which I can then loop through with a for loop. How would I do this? My understanding is that I'd need to declare the array type, and I don't know what data type I'd use. Thanks.
*Edit* I forgot to mention that these function calls will be to functions inside several separate objects of different types.