Java 15: Wrong error "Required type: Object; Provided: <lambda parameter>"
Answered
Hi,
I just switched my Spring Boot project from Java 14 to Java 15. Now I get errors in "stream.forEach()" on "java.util.List". I call a method there that takes an "Object" instance as the parameter. But IntelliJ complains "Required type: Object; Provided: <lambda parameter>". And IntelliJ doesn't show which code inspection that is - it should, optionally.
Anyhow, below's a short screencast. Does anybody know how to fix that?

Regards,
Karsten Silz
Please sign in to leave a comment.
There were other lambda errors with JDK 15: IntelliJ couldn't infer the class of at least some lambda parameters anymore. It then marked the methods I called on these lambda parameters as unknown.
I got fed up and switched back to Java 14, and all of this trouble went away.
Hello,
Can you please provide a little code sample where the issue is reproduced for you (to reproduce on our side). Thank you
@... Sorry, I didn't want to spend any more time on this. I can't share my code because it's proprietary, so I'd have to create a sample project just for this. I didn't.
I hope somebody else reports it so that it'll be fixed by the time I switch to Java 16.
Same issue. Using correto and/or OpenOracle Jdk 20 and facing the same issue.
Not sure if this the compiler or my code.
Map<String,String> getResponseHeaders( HttpServletResponse httpResponse ) {
return httpResponse.getHeaderNames().stream()
.collect( key -> Collectors.toMap( key, httpResponse.getHeader( key ), HashMap::new ) );
“key” comes with the message for
required type:String
Provided: <lambda parameter>
I also tried using .map(String::toString) to force a string to be provided. I hope it is my code.
Behaviour of IDEA is correct: trying with
it's not compiled with e.g. j19:
You can submit a feature request here to introduce a quick fix for such case.
Pls attach a sample project if it compiles for you with Java.