Created
July 21, 2015 16:51
-
-
Save tobyweston/0fbb8eb114db48596e6b to your computer and use it in GitHub Desktop.
Java 8 to Scala bridge methods
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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