Skip to content

type mismatch with example #197

@rongpenl

Description

@rongpenl

Hi,

I am following this tutorial. Awesome work. However, I couldn't get this example working with the code provided.

trait Stream[+T] {
    def prepend[U >: T](elem: U) : Stream[U] = Stream.cons(elem, this)
}

Compiling the code above gives me error as following.

polymorphism.scala:15: error: type mismatch;
 found   : Stream[T]
 required: scala.collection.immutable.Stream[?]
           def prepend[U >: T](elem: U) : Stream[U] = Stream.cons(elem, this)

Did I miss something?

* def prepend [U >: T](elem: U): Stream[U] = Stream.cons(elem, this)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions