Java 8 introduces SAM(Single Abstract Method) type to embrace functional programming.
SAM type is enabled by -Xexperimental flag in scala 2.11.x flags. In build.sbt, add below:
scalacOptions := Seq("-unchecked", "-deprecation", "-Xexperimental")
Interoperating with Java requires SAM, which also generates more efficient byte code since SAM has a native byte code counterpart. Using anonymous class for event handler or callback can be more pleasant in Scala just as in Java.
So for the stream example, if compiler has the -Xexperimental flag, scala will automatically change the function to java’s function, which grant scala user a seamless experience with the library.
Interoperating with Java requires SAM, which also generates more efficient byte code since SAM has a native byte code counterpart. Using anonymous class for event handler or callback can be more pleasant in Scala just as in Java.
Reference:
https://herringtondarkholme.github.io/2015/01/24/scala-sam/
No comments:
Post a Comment