2 ms·
This code uses an enhanced for loop to step through a collection, calculating total as a side effect without using the loop variable order. That seems like a v
by userbinator 4y ago
This code uses an enhanced for loop to step through a collection, calculating total as a side effect without using the loop variable order.
That seems like a very contrived example. I don't work with Java regularly, but wouldn't that be better written as something like this?
int total = max(orders.length, LIMIT);
- kaba0 4y agoIt is a contrived example, but the idea/code pattern isn’t — I have written plenty of code where I had to iterate over a collection with a for loop, but didn’t use the exact element. But obviously for typical usage one should probably just use the stream API.
- frant-hartm 4y agoOrders may be Iterable, which doesn't have length/size().