问题
My insertion sort method is declared using this statement:
public static <AnyType extends Comparable<? super AnyType>>
void insertionSort(AnyType[] a){
I am having trouble understanding how to make this generic array type parameter accept an array of primitive type int.
How would I call this method with int[] as my parameter, or at least how would it be used to sort an int array?
回答1:
Use a wrapper class - Integer. There is something called autoboxing which means that if you pass an argument of primitive type int it will convert automatically to Integer :-)
http://en.wikipedia.org/wiki/Primitive_wrapper_class https://docs.oracle.com/javase/tutorial/java/data/autoboxing.html
来源:https://stackoverflow.com/questions/30008538/how-to-use-an-integer-array-for-a-generic-method