If it were Python, I could probably write something like:
sum(key.price * val for (key, val) in cart.items())
But the Java example makes me think "Wait, what?"Personally, the lesson I'm drawing is that your library shouldn't actively fight the native syntax of the language you are using - just use what your language provides, that's the cleanest and easiest way to do it.
But I guess people's tastes are different.