I guess (or at least it is an alternative) this way is more performant:
public static IntStream baz(List<Integer> list)
{
return list.stream().mapToInt(Integer::intValue);
}
since the function Integer::intValue
is fully compatible with ToIntFunction
since it takes an Integer
and it returns an int
. No autoboxing is performed.
I was also looking for an equivalent of Function::identity
, i hoped to write an equivalent of your bar
method :
public static IntStream qux(List<Integer> list)
{
return list.stream().mapToInt(IntFunction::identity);
}
but they didn't provide this identity
method. Don't know why.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…