Scala LanguageSingle Abstract Method Types (SAM Types)

Remarks

Single Abstract Methods are types, introduced in Java 8, that have exactly one abstract member.

Lambda Syntax

NOTE: This is only available in Scala 2.12+ (and in recent 2.11.x versions with the -Xexperimental -Xfuture compiler flags)

A SAM type can be implemented using a lambda:

2.11.8
trait Runnable {
  def run(): Unit
}

val t: Runnable = () => println("foo")

The type can optionally have other non-abstract members:

2.11.8
trait Runnable {
  def run(): Unit
  def concrete: Int = 42
}

val t: Runnable = () => println("foo")