Hi - I am trying to create a MergeSort class. In order to do so, I have to create a temporary generic array in MergeSortedHalves in order to copy the elements in to. I know in order to create a generic array one must create an object array and cast it to a generic array. However, I cant find what I am doing wrong. I have created generic arrays before fine, but im having trouble with this one.
private static <Type extends Comparable<? super Type>> void mergeSortedHalves(Type[] arr, int left, int middle, int right) {
Type [] temp = (Type []) new Object[right - left + 1];
...
}
I get the following exception:
Exception in thread "main" java.lang.ClassCastException: [Ljava.lang.Object;\
Any hints on what I am doing wrong? Thanks