Array of references?
I have 4 object arrays that hold different object types. I want to make an array to hold the references to each of these object arrays. What would be the type of this array? In C I would make an array of pointers but since pointers don't exist in java i don't know what to do.
While I could be wrong, and if I am I will learn something. I am fairly confident that an array of objects is an array of references.
I have to ask why? This sounds like a bad idea.
Here's an example of what I'm trying to do:
Eventually, there will be about 20 different types in this array. Not having something like this makes it so I have to copy-paste blocks of codes, only changing the array being used in the block. This makes my code long and repetitive.
Bullet bullets = new Bullet;
RPG rpgs = new RPG;
Grenade grenades = new Grenade;
Shrapnel shrapnel = new Shrapnel;
//something particleType = new something;
//particleType = bullets;
//particleType = rpgs;
//particleType = grenades;
//particleType = shrapnel;
It sounds like you are dealing with an arsenal containing a whole lot of (arrays of) things.
You could consider making an Arsenal class. It would have the bullets, rpgs etc as part of its state and may very well have methods to do the things you are intending doing with the bullets etc in these "blocks of code".
^ Ok, that's a good idea. Just out of curiosity though, is there no way to make an array that holds arrays of different types? What if I got the memory address of each array and saved as an int or something, which would then go into an int?
There is but I am reluctant to tell you as once again it is a bad idea.
Alright. Thanks for the quick help, anyway. Creating the "Arsenal" class was a better solution than what I had in mind.
You can make a super class which has all the similarities of the items and then create a two d array of that super class.