JAVA array sorting method, Arrays.sort () method question?

this API specifies that the entity bean implements the comparable interface and overrides the compareTo method. Why not change API to Arrays.sort (Compatable [] com)?

Mar.28,2021

The real reason for

is that it has to be designed this way because of a feature of the Java array. Simply put, the runtime type of the Java array is not determined by its element type, but by the type when it is actually instantiated.

for example, the following array:


Compatable[]sort

int [] a ={1,2,3,6,4,3,23,5,6,7,9};

Arrays.sort(a);

//a = [1, 2, 3, 3, 4, 5, 6, 6, 7, 9, 23]
Menu