This is from Professor Mark Weiss in his book Data Structures and Algorithm Analysis in Java
public class BinaryHeap<AnyType extends Comparable<? super AnyType>>{
private void enlargeArray( int newSize ){
AnyType [] old = array;
array = (AnyType []) new Comparable[ newSize ];
for( int i = 0; i < old.length; i++ )
array[ i ] = old[ i ];
}
}
I was wondering why do we declare an array with a type of interface Comparable since we have to convert the Comparable[] to an AnyType[]? Any design philosophy in there?
Classobject, but it's still better to perform the unchecked casts on the elements (which are actually expected to have the type you're casting them to) than the array (which definitely isn't of the type you'd be casting it to).