hi,
i have a problem i can't figure out. i'm trying to create a tree structure in a class. to do that i have a class "Knod" and a class "Leaf". the class "Tree" is an ArrayList of arrays. and these arrays contain a boolean, a Knod or Leaf-class and 2 ints (defining the next Knod or Leaf)
as you can see i use an array of objects to make this work.
now i want to get the value of the Boolean. usually you would do
or in my case
but since i made an array of object's he doesn't recognize this function.
so the actual question is, how can i put multiple classtypes in 1 array and still use all the functions?
tnx
i have a problem i can't figure out. i'm trying to create a tree structure in a class. to do that i have a class "Knod" and a class "Leaf". the class "Tree" is an ArrayList of arrays. and these arrays contain a boolean, a Knod or Leaf-class and 2 ints (defining the next Knod or Leaf)
Code:
public class Tree{
private int init;
private ArrayList<Object[]> boom;
public Tree(){
this.init = 0;
this.boom = new ArrayList<Object[]>();
}
public void newLeaf(double[] waarden){
Object[] arr = new Object[2];
//false = leaf
arr[0] = new Boolean(false); //true = Knod
arr[1] = new Leaf(waarden);
this.boom.add(arr);
}
public void newKnod(double[] waarden, int trueVal, int falseVal){
Object[] arr = new Object[4];
//false = leaf
arr[0] = new Boolean(true); //true = Knod
arr[1] = new Knod(waarden);
arr[2] = new Integer(trueVal);
arr[3] = new Integer(falseVal);
this.boom.add(arr);
}
}
now i want to get the value of the Boolean. usually you would do
Code:
bool.booleanValue()
Code:
this.boom.get(id)[0].booleanValue()
so the actual question is, how can i put multiple classtypes in 1 array and still use all the functions?
tnx
Comment