Hello all,
I declare an array of objects with a default capacity of 2 and I am trying to expand capacity once the limit is meet. I am calling the "expandCapacity" method which creates a new array of twice the old size and copies the old array into the new one. I get the following error:
"Exception in thread "main" java.lang.ClassCastException: [Ljava.lang.Object; cannot be cast to [LcharFreqNode;
at driver.main(driver.java:45)"
function call from main
if (count >= mycharFreqNode.length) mycharFreqNode = arrayOps.expandCapacity(mycharFreqNode);
expandCapcity method
public class arrayOps<T> { public static <T> T[] expandCapacity(T[] data){ T[] larger = (T[]) (new Object [data.length *2]); for (int index = 0; index < data.length; index++) larger[index] = data[index]; data = larger; return larger; } }