I have created a generic class that creates an ArrayList
of Numbers
public class MyMathClass<T extends Number> {
private ArrayList<T> myarraylist;
public MyMathClass(ArrayList<T> arrayList){
myarraylist = arrayList;
}
I tried to create a method that basically calculates the average of the given ArrayList
public double average(){
var average = 0;
for(int i = 0 ; i <= myarraylist.size(); i++){
average += myarraylist.get(i);
}
}
but when try to add the average with the value at index i, I get this error: "operator + cannot be applied to 'int' , 'T'