Loading...
Logo
Processing Forum
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. 
Thanks.

Replies(8)

I normally move questions without code out of Programming Questions into General Discussion, but I will wait to see your code example...
Your question is a bit vague right now. If you have an array list in each sub-class, why make an array of array lists?
I don't see why you cannot " make calls to objects inside them" (what objects? you don't call objects, BTW, but their methods).
class Base{
 ArrayList<Base> objects;
 Base(){
 
 }
 void runme(){

 }
}

class SubBase extends Base{
 SubBase(){
  
 }
 void runme(){
  super.runme();
  objects.get(23).runme();
 }
}
Should get you started. I'm a little on the fence with the java generics here, which seems to me like an attempt at strong typing after the fact. 

No one needs strong typing!!  


" No one needs strong typing!!"
Then use JavaScript!
Strong typing is the racial discrimination of the coding world.
Whatever...

I wouldn't try to use a weakly or dynamically typed language in a large project with lot of coders. And the coding facilities offered by strong typing: good autocompletion, accurate refactoring, early catch of coding errors, etc. are well worth the implied verbosity (that can be reduced by type inference, eg. in Scala).
I like both styles myself. Although I like strong typing a little more.  hehe 

Python, Lua, CoffeeScript and JavaScript are the best examples for weak typing though.
But all of them are script languages.

Strong typing is best for compiled and speedier languages! 
I think I found a different, less messy way to do what I needed. I'm just going to have the 4 ArrayLists, a "active" container for each type to hold a copy of the desired object (or a way to call methods in that object), and boolean switches to let the program know which copy is actually "active". Thanks for your help.