I am working on an assignment to write a generic class called MyStatisticsClass with type parameter T where T is a numeric object. with a method called standardDeviation that takes a ArrayList of type T and returns a double. I am getting the following error when I try to compile:
- MyStatisticsClass.java:27: standardDeviation(java.util.ArrayList<T>) in MyStatisticsClass<T> cannot be applied to (java.util.ArrayList<java.lang.Double>)
-
Double result = standardDeviation(numbers);
Here are some tid bits of the code I have:
- public static void main(String[] args)
-
{
-
ArrayList<Double> numbers = new ArrayList<Double>();
-
//some random numbers are assigned to numbers here
-
Double result = standardDeviation(numbers);//this is causing the error
-
}
-
-
public double standardDeviation(ArrayList<T> a)
-
{
-
double average = calcAverage(a);
-
double top = 0.0;
-
//calculate the standard deviation
-
for (int i = 0; i < a.size(); i++)
-
{
-
top = top + Math.pow(a.get(i).doubleValue() - average, 2);
-
}
-
return Math.sqrt(top / average);
-
}
Anyone know what I am doing wrong? I can't seem to figure it out! Thanks for any help.