我正在尝试使用Scala Test测试一个Java 8类,其中涉及到
rx.Observable
。根据Scala 2.12.0-M3
的发布说明:
然而,使用Gradle和IntelliJ时,我无法使以下代码编译成功:SAM类型的LAMBDA语法(实验性特性):从M3开始,此功能还未默认启用。您可以通过
-Xexperimental
编译器选项启用它。启用该选项后,与Java 8类似,Scala 2.12允许通过传递lambda来实例化任何具有单个抽象方法的类型。
val o: rx.Observable[util.Map.Entry[String, _ <: util.Collection[String]]] = ???
val scheduler = new TestScheduler()
scheduler.createWorker().schedule(_ => o.foreach { }) // The argument is an Action0, which has a 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'
}