为什么在空intStream上的summaryStatistics()方法返回整数的最大值和最小值作为流中存在的最大和最小int值?
IntStream intStream = IntStream.of();
IntSummaryStatistics stat =
intStream.summaryStatistics();
System.out.println(stat);
输出:
IntSummaryStatistics {count = 0,sum = 0,min = 2147483647,平均值= 0.000000,max = -2147483648}
难道不应该认为是错误的结果吗?
此行为记录在Javadoc中:
/**
* Returns the minimum value recorded, or {@code Integer.MAX_VALUE} if no
* values have been recorded.
*
* @return the minimum value, or {@code Integer.MAX_VALUE} if none
*/
public final int getMin() {
return min;
}
/**
* Returns the maximum value recorded, or {@code Integer.MIN_VALUE} if no
* values have been recorded.
*
* @return the maximum value, or {@code Integer.MIN_VALUE} if none
*/
public final int getMax() {
return max;
}