Quantcast
Channel: Choosing between overloaded methods if actual parameter is a lambda - Stack Overflow
Browsing index pages (3 articles)

Choosing between overloaded methods if actual parameter is a lambda

In Java 1.8, the following lambda expression complies with both Runnable and Callable functional interfaces: () -> { throw new RuntimeException("FIXME"); } Still, if I submit it to an...

View Article


Answer by thecoop for Choosing between overloaded methods if actual parameter...

I believe this is because Callable declares a return type, and Runnable does not. From the JLS section 15.12.2.5, the overload with the most specific type is chosen, if there is one unambiguously most...

View Article


Answer by biziclop for Choosing between overloaded methods if actual...

Although @thecoop's answer is correct, there is another aspect of the lambda mechanism worth mentioning. Lambdas with block bodies fall into two categories: void-compatible and value-compatible. The...

View Article
Browsing index pages (3 articles)


Latest Images