I'm having trouble with a generic method that can accept ArrayLists of type integer and type double.
The program fails to compile because it says myList is of type "T" and i is of type "double".
Here's a snippet of code:
public double calculateTotals(ArrayList<T> list) { private ArrayList<T> myList = new ArrayList<T>(10); myList = list; for (double i : myList) { ....do stuff } } public static void main(String args[]) { ArrayList<Double> doubleArrayList = new ArrayList<Double>(10); ...populate array... double totals = calculateTotals(doubleArrayList); }
I'm trying to figure out what I'm doing wrong. I thought myList would become an arraylist of type double since that's what I'm passing in.
Any clues would be greatly appreciated!
Thanks!