Problem with versions of scala (2.11 and 2.12)


(topic withdrawn by author, will be automatically deleted in 24 hours unless flagged)


You mean it compiles with 2.12, but not with 2.11, right?

Your code uses a 2.12 feature, where it automatically casts a function to a type that has a single abstract method, and that feature is not available in 2.11.

For example, a type with a single abstract method would be:

trait MySam {

** def makeBigger(i: Int): Int**


where makeBigger is abstract. To create an anonymous instance of MySam, in Scala 2.11, you would do like this:

val mySam1: MySam = new MySam {

** def makeBigger(i: Int): Int = 10 + i**


In Scala 2.12, there is a shorter notation for this, which is:

val mySam2: MySam = (i: Int) => 10 + i

(it’s actually not just sugar, but the implementation on the JVM side is also special, which is possible since Scala 2.12 targets Java 8, which has special support for types with a single abstract method, also known as lambdas)

You need to rewrite your code to 2.11 style, so it needs to look something like:

def seqAsObjWriter[T](field: String) (implicit format: OWrites[T]): OWrites[Seq[T]] = new OWrites[Seq[T]] { … }