/* TestGenerics6.java CIS 260 David Klick 1/28/2010 This program demonstrates using the ? wildcard in Java generics. This is basically the same as a program presented in the text for the course. */ import java.util.Arrays; import java.util.ArrayList; public class TestGenerics6 { public static void main(String[] args) { Integer[] inums = { 2, 4, 6, 8, 10 }; ArrayList iarray = new ArrayList(Arrays.asList(inums)); Double[] dnums = { 8.2, 3.7, 6.3, 2.8, 9.2 }; ArrayList darray = new ArrayList(Arrays.asList(dnums)); System.out.printf("Sum: %.2f\n", sum(iarray)); System.out.printf("Sum: %.2f\n", sum(darray)); } private static double sum(ArrayList a) { double sum = 0.0; for (Number n : a) sum += n.doubleValue(); return sum; } }