I don't know what to do about my generic array. I keep getting this error
Exception in thread "main" java.lang.ClassCastException: [Ljava.lang.Object; cannot be cast to [Ljava.lang.Comparable;
the error is related to this bit of code
T[] a = (T[]) new Object[temp];
My class extends comparable, and I don't know why I keep getting this error. Any hints on how to fix this will be greatly appreciated. Here is the code.
public void balance()
{
int temp = size();
int low = temp -(temp - 1);
T[] a = (T[]) new Object[temp];
reset(INORDER);
for (int i =0;i<temp; i++)
{
a[i]= getNext(INORDER);
root = null;
insertRec( a, 0 ,temp-1);
add((T) a [i]);
}
}
I don't have any issues with the rest of the code, but thought it would be helpful to see the whole method. This is part of a much larger class that manipulates Binary search trees, this method is supposed to balance the tree.