My textbook says the type bound inside the angled brackets of the code below is incorrect. Then it said adding "extends Comparable" inside the angle brackets is naive. I typed out the paragraph from the textbook. Why does it say this solution is naive?
"Suppose we want to write a findMax routine. Consider the code below. This code cannot work because the compiler cannot prove that the call to compareTo at line 6 is valid; compareTo is guaranteed to exist only if AnyType is Comparable. We can solve this problem by using a type bound. The type bound is specified inside the angle brackets <>, and it specifies properties that the parameter types must have. A naive attempt is to rewrite the signature as:
public static <AnyType extends Comparable>...
This is naive because, as we know, the Comparable interface is now generic."
public static <AnyType> AnyType findMax( AnyType arr)
int maxIndex = 0;
for(int i=1; i<arr.length; i++)
if(arr[i].compareTo(arr[maxIndex]) > 0)
maxIndex = i;