79

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?

oxbow_lakes
  • 133,303
  • 56
  • 317
  • 449

1 Answers1

121

Use Compound Type:

trait Narrowable[A] extends Iterable[A] {
  def narrow[B <: A with AnyRef] : Iterable[B]
}
Walter Chang
  • 11,547
  • 2
  • 47
  • 36