Explicitly multiplying values as longs
- by Bill Szerdy
I understand that all math is done as the largest data type required to handle the current values but when you transverse a loop how do you explicitly multiply longs? The following code returns 0, I suspect, because of an overflow.
long result = 0L;
List<Long> temp = (List<Long>) getListOfIntegers();
for (int i = 0; i < temp.size(); i++) {
result *= temp.get(i).longValue();
}
System.out.println(result);