tags:

views:

280

answers:

1

I want to be able to declare something like this:

trait Narrowable[A] extends Iterable[A] {

    def narrow[B <: A & B <: AnyRef] : Iterable[B]

}

That it, the type B should be both a subtype of A and AnyRef. Is this possible?

+13  A: 

Use Compound Type:

trait Narrowable[A] extends Iterable[A] {
  def narrow[B <: A with AnyRef] : Iterable[B]
}
Walter Chang
Thank you! Have been searching for this for a while! :)
Martin McNulty