I have the following code:
final var fieldValuesStream = items.stream()
.map(person -> PersonFieldGetter.getFieldValueAsNumber(functionsParameters.getFieldName(), person)) // Number
.mapToDouble(number -> number.doubleValue());
IDEA highlights "number -> number.doubleValue()" with the message:
Lambda can be replaced with method reference
Replace Lamda with method reference
But when I change the code to .mapToDouble(Number::doubleValue) a compile error happens:
QueryProcessor.java:31:34 java: incompatible types: invalid method reference method doubleValue in class java.lang.Number cannot be applied to given types required: no arguments found: java.lang.Object reason: actual and formal argument lists differ in length
Full source code
Why is this happening?
Project to reproduce the problem
EDIT: Added link to GitHub project with example project that is failing to build using:
IntelliJ IDEA 2021.2.3 (Ultimate Edition)
Build #IU-212.5457.46, built on October 12, 2021
Runtime version: 11.0.12+7-b1504.40 amd64
VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o.
SDK: Oracle OpenJDK 17.0.1