Scala 2.12 and Java 8 SAM interop doesn't compile -
i'm trying test java 8 class using rx.observable
scala test. per scala 2.12.0-m3
release notes:
lambda syntax sam types (experimental) of m3, feature not yet on default. can enable
-xexperimental
compiler option.when option enabled, similar java 8, scala 2.12 allows instantiating type 1 single abstract method passing lambda.
however, using gradle , intellij, can't following compile:
val o: rx.observable[util.map.entry[string, _ <: util.collection[string]]] = ??? val scheduler = new testscheduler() scheduler.createworker().schedule(_ => o.foreach { }) // argument action0, has sam void call()
build.gradle:
apply plugin: 'scala' group = 'name.abhijitsarkar.scala' version = '1.0-snapshot' tasks.withtype(scalacompile) { scalacompileoptions.useant = false scalacompileoptions.additionalparameters = ["-feature", "-xexperimental"] targetcompatibility = "1.8" } dependencies { compile 'org.scala-lang:scala-library:2.12.0-m3' compile 'com.typesafe.akka:akka-stream-experimental_2.11:2.0.3' compile 'io.reactivex:rxjava:1.1.0' testcompile 'org.scalatest:scalatest_2.12.0-m3:3.0.0-m12' }
scheduler.createworker().schedule(_ => o.foreach { }) // argument action0, has sam void call()
that try pass "function" 1 argument (rather anonymous instance of interface/trait 1-argument sam). _
indicates don't use argument in body. action0
's call()
takes 0 arguments, try () => o.foreach { }
instead.
Comments
Post a Comment