Error
The method averagingInt(ToIntFunction<? super T>) in the type Collectors is not applicable for the arguments ()
Error Type
Compile Time ( Java 8 )
Sample Code
Set<Integer> intSet = new HashSet<Integer>();
intSet.add(1);
intSet.add(2);
intSet.add(3);
intSet.add(4);
System.out.println(intSet.stream().collect(Collectors.averagingInt()));
Cause
The method averagingInt expects the argument as function and not the String.
Resolution
Specify the argument as function.
Set<Integer> intSet = new HashSet<Integer>();
intSet.add(1);
intSet.add(2);
intSet.add(3);
intSet.add(4);
System.out.println(intSet.stream().collect(Collectors.averagingInt(p->(Integer)p)));
The method averagingInt(ToIntFunction<? super T>) in the type Collectors is not applicable for the arguments ()
Error Type
Compile Time ( Java 8 )
Sample Code
Set<Integer> intSet = new HashSet<Integer>();
intSet.add(1);
intSet.add(2);
intSet.add(3);
intSet.add(4);
System.out.println(intSet.stream().collect(Collectors.averagingInt()));
Cause
The method averagingInt expects the argument as function and not the String.
Resolution
Specify the argument as function.
Set<Integer> intSet = new HashSet<Integer>();
intSet.add(1);
intSet.add(2);
intSet.add(3);
intSet.add(4);
System.out.println(intSet.stream().collect(Collectors.averagingInt(p->(Integer)p)));