Java 1.7: Sum of Iterable<T extends Number>
问题 I need to create a helper method which allows to create a sum of any Iterable<? extends Number>, because we have many vectors and require a fast method to determine the sum, so I created the following method: static Integer sum(Iterable<Integer> it) { Integer result = 0; for(T next : it) { result += next; } return result; } This method only works for ints however, but we also have doubles and longs. Because you can't have two methods with the same signature (Our compiler thinks Integer sum