Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Java 8 to Scala bridge methods
package bad.robot.radiate
import java.util.concurrent.Callable
import java.util.function.{Consumer, Supplier}
object FunctionInterfaceOps {
implicit def toConsumer[A](function: A => Unit): Consumer[A] = new Consumer[A]() {
override def accept(arg: A): Unit = function.apply(arg)
}
implicit def toSupplier[A](function: => A): Supplier[A] = new Supplier[A]() {
override def get(): A = function
}
implicit def toRunnable(function: => Unit): Runnable = new Runnable {
override def run(): Unit = function
}
implicit def toCallable[A](function: => A): Callable[A] = new Callable[A] {
override def call(): A = function
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment