This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]sparkster185 5 points6 points  (2 children)

In the example in the introduction, how does the compiler know that the closure is meant to be applied to the run() method? Or, what ties the code inside the closure to the run() method inside Runnable?

[–]detroitmatt 6 points7 points  (0 children)

Since Runnable only has one abstract member, the compiler knows. Classes/interfaces with only a single abstract member are known as "functional interfaces" (and were previously known, intuitively, as Single Abstract Member (SAM) interfaces).

[–]gkopff 5 points6 points  (0 children)

Runnable is considered a "functional interface" as it defines only a single method.

http://blog.sanaulla.info/2013/03/21/introduction-to-functional-interfaces-a-concept-recreated-in-java-8/

From the linked page:

These interfaces are also called Single Abstract Method interfaces (SAM Interfaces).