I am currently working on an assignment that puts concepts Comparableinto the application.
I wrote this simple method that allows you to enter an array Comparable[]. This method returns the minimum value of any given input array. Using the method .compareTo(), I can really extend this method to allow object types to really do anything, be it a custom implementation, such as a class Point(which we did for the purpose, but not shown here).
public static Comparable getMinimum(Comparable[] inputArray)
{
Comparable newObj = inputArray[0];
for(int i = 0; i < inputArray.length; i++)
{
Integer retValue = (inputArray[i]).compareTo(newObj);
if(retValue < 0)
{
newObj = inputArray[i];
}
}
return newObj;
}
My question is: what is this type Comparable? Looking at the Java API, he really showed little. Why do we use the type Comparableas opposed to the type Objectthat also includes types such as int, double, String, etc.