I have a following function:
def removeLast(list: List[Int]): List[Int] = list match {
case List() => List()
case List(x) => List()
case x :: xs => x :: removeLast(xs)
}
When I define it and use it from the sbt console everything works just fine. But when I create a worksheet in Intellij IDEA and try to run it then the following exception appears:
java.lang.NoSuchMethodError: scala.collection.immutable.$colon$colon.hd$1()Ljava/lang/Object; at week5.A$A26$A$A26.removeLast(lists.sc8362409100671270508.tmp:30) at #worksheet#.#worksheet#(lists.sc8362409100671270508.tmp:33)
In addition, when I change last line to:
case x :: xs => 1 :: removeLast(xs)}
then it works.
What might the problem be?
I had this issue. Agree with Andrzej, idea uses its own compiler, so you have to disable it somehow. Go to Settings->Scala->Worksheet and uncheck "Run worksheet in the compiler process".
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With