This will work, but the i -> i
is doing some automatic unboxing which is why it "feels" strange. mapToInt
converts the stream to an IntStream
"of primitive int-valued elements". Either of the following will work and better explain what the compiler is doing under the hood with your original syntax:
integers.values().stream().mapToInt(i -> i.intValue()).sum();
integers.values().stream().mapToInt(Integer::intValue).sum();
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…