I have following code to generate summary for the list of values(Integer for this example). When I use method reference to get the values it is failing at run time giving ArrayIndexOutOfBoundException, but supplier is working fine.
static void test1() {
List<Integer> intList = Arrays.asList(1, 2, 3, 4, 5);
IntSummaryStatistics stWorking = intList.stream().collect(Collectors.summarizingInt(num -> num));
System.out.println(stWorking);
IntSummaryStatistics stRuntimeError = intList.stream().collect(Collectors.summarizingInt(intList::get));
System.out.println(stRuntimeError);
}
Can somebody please help to understand what is the reason for this?
Thanks.