title: Intellij IDEA java.lang.NoSuchMethodError: scala.collection.immutable.$colon$colon.hd$1()Ljava/lang/Object
body: <p>I have a following function:</p>
  
  <pre><code>def removeLast(list: List[Int]): List[Int] = list match {
    case List() =&gt; List()
    case List(x) =&gt; List()
    case x :: xs =&gt; x :: removeLast(xs)
  }
  </code></pre>
  
  <p>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:</p>
  
  <blockquote>
    <p>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)</p>
  </blockquote>
  
  <p>In addition, when I change last line to:</p>
  
  <pre><code>case x :: xs =&gt; 1 :: removeLast(xs)}
  </code></pre>
  
  <p>then it works.</p>
  
  <p>What might the problem be?</p>