Kotlin and SAM interface with two parameters

+1 as more java 8 libraries arise, SAM’s like Function, Consumer are everywher in java libs. For polyglott projects, one would like Kotlin’s type inference to recognize SAM’s. I know type inference of SAM’s works for methods defined in “real” java classes, however it fails when defined inside a kotrlin class.

e.g. a method
fun foo(Consumer<Bar> c)

has to be called from kotlin like this
obj.foo( Consumer { bar -> ... })

vs. java8
obj.foo( bar -> ... ).

IMO kotlin type inference should enable
obj.foo { bar -> ...}

2 Likes