如何使用整数数组进行泛型排序方法?

时间:2022-02-10 14:23:10

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 applying this generic array will allow me to use an array of primitive type int

我无法理解如何应用这个通用数组将允许我使用基本类型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.

我如何使用int []作为我的参数调用此方法,或者至少如何使用它来对int数组进行排序。

1 个解决方案

#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 :-)

使用包装类 - 整数。有一种称为自动装箱的东西,这意味着如果你传递一个原始类型int的参数,它将自动转换为整数:-)

http://en.wikipedia.org/wiki/Primitive_wrapper_class https://docs.oracle.com/javase/tutorial/java/data/autoboxing.html

#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 :-)

使用包装类 - 整数。有一种称为自动装箱的东西,这意味着如果你传递一个原始类型int的参数,它将自动转换为整数:-)

http://en.wikipedia.org/wiki/Primitive_wrapper_class https://docs.oracle.com/javase/tutorial/java/data/autoboxing.html