Java stream: after map () conversion, Collectors.maxBy (Double::max) reports an error
error message
age is Integer type, (Integer::max), (Integer::min) is correct
salary is Double type, (Double::max), (Double::min) error:
Bad return type in method reference: cannot convert double to int
try rebuid, recompile, mvn clean/compile are all invalid
related codes
@Test
public void minByOrMaxByTest() {
// maxBy minBy , Double(salary)maxBy() TODO
System.out.println(Employee.EMPLOYEE_LIST.parallelStream().map(Employee::getAge).collect(Collectors.maxBy(Integer::min)).orElse(null));
System.out.println(Employee.EMPLOYEE_LIST.parallelStream().map(Employee::getAge).collect(Collectors.minBy(Integer::min)).orElse(null));
System.out.println(Employee.EMPLOYEE_LIST.parallelStream().map(Employee::getSalary).collect(Collectors.minBy(Double::min)));
System.out.println(Employee.EMPLOYEE_LIST.parallelStream().map(Employee::getSalary).collect(Collectors.maxBy(Double::max)));
}
@Data
@AllArgsConstructor
public class Employee {
private String name;
private Integer age;
private Double salary;
}