Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Intellij IDEA java.lang.NoSuchMethodError: scala.collection.immutable.$colon$colon.hd$1()Ljava/lang/Object

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?

like image 692
Dawid Mazuruk Avatar asked Oct 15 '14 19:10

Dawid Mazuruk


1 Answers

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".

like image 134
Tomek Kozlowski Avatar answered Sep 22 '22 08:09

Tomek Kozlowski