Skip to content

java.util.function.Consumer not working with lambda #12380

Closed
@AugustNagro

Description

@AugustNagro

Compiler version

3.0.0-RC3

Minimized code

val l = java.util.List.of(1, 2, 3)
l.forEach(x => println(x))

Output

[error] 4 |  l.forEach(x => println(x))
[error]   |              ^
[error]   |object creation impossible, since def accept(x$0: T): Unit in trait Consumer in package java.util.function is not defined 
[error]   |(Note that
[error]   | parameter T in def accept(x$0: T): Unit in trait Consumer in package java.util.function does not match
[error]   | parameter Int in final def accept(x: Int): Unit in anonymous class Object with java.util.function.Consumer[? >: Int] {...}
[error]   | )

This works:

val l = java.util.List.of(1, 2, 3)
val consumer: java.util.function.Consumer[Int] = x => println(x)
l.forEach(consumer)

Maybe related to @smarter's PR #12131?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions