I have two functions
public static double avg(int[] values) {
if(values == null || values.length == 0) return -1;
double sum = 0;
for(int value:values) {
sum = sum + value;
}
return (sum/values.length);
}
public static double avg(double[] values) {
if(values == null || values.length == 0) return -1;
double sum = 0;
for(double value:values) {
sum = sum + value;
}
return (sum/values.length);
}
I am using Spel expression engine to evaluate the expressions. When i deploy this code and invoke expression avg({3,4,5}) or avg({3.0,4.0,5.0}), i get the below error,
Caused by: org.springframework.expression.spel.SpelEvaluationException: EL1033E:(pos 0): Method call of 'avg' is ambiguous, supported type conversions allow multiple variants to match
Does int[] array implicitly get converted into double[] during evaluation?
Shall i make it single function avg(double[] values)??
Thanks,
Vijay Bhore