Scala generic: type mismatch

Viewed 534

In the purpose of learning, I would like to understand how "::" class is working.
So I decided to create my own but instead of calling it "::" I want to call it ":++:"

From List.scala source code, the University of Helsinki and Programming In Scala 2nd edition (Chapter 22) I should write:

abstract class List[+A] {
    def isEmpty: Boolean
    def head: A
    def tail: List[A]
}

final case class :++:[A](head: A, tail: List[A]) extends List[A] {
  override def isEmpty: Boolean = false
}


I can create "::" objects

new ::(1, List(2))

But I can't create my ":++:" objects:

new :++:(1, List(2))
<console>:12: error: type mismatch;
found   : List[Int]
required: List[?]
            new :++:(1, List(2))

Where is my mistake?

2 Answers
Related