In Java, I'm working on a function to return the highest value in an array. I'm writing it such that it does not care about the type of parameter using bounded parameters (I think). I'm getting an error in the main function in detecting the signature of the function.
I followed what I saw in various tutorial pages which don't seem to indicate the call will have any problem.
public static <N extends Number> N getMax (N [] numberArray){
N value = numberArray [0];
for (int i = 0; i < numberArray.length; i++){
if((double) numberArray[i] > (double) value)
value = numberArray[i];
}
return value;
}
public static void main (String [] args ){
double[] array = {1,2,3,1,-10,2};
System.out.println(getMax(array));
}
EDIT: A bit of clarification on the issue. I'm doing this as part of an assignment in which I need to write a function that returns the max value of an array. Based upon that, I'm assuming that I cannot expect any particular input and the main function was just demonstrating the issue.