0

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
  • 2
    I don't believe you can, you'd have to use Integer instead. Commented May 2, 2015 at 23:16

1 Answer 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 :-)

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.