Question: hi, I have an interface which has a method that returns the index of smallest element in the array. the interface has

hi, I have an interface which has a method that returns the index of smallest element in the array.

the interface has and the method returnes int (int min () )

in the class of implemention has an generic array which defiend like this:

T Myarray[]; Myarray = (T[]) new Comparable[size]; # note : note sure if this way best way to create generic array

My question is how i can make the min method work for the generic array to make comparison, since every time it gives me an error: at java.lang.Integer.compareTo(Unknown Source), and how i can initialize the generic array in the main class with one parameter(the size).

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!