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?