2

I'm reading the book "programming in scala", and found the variance positions are hard to understand.

trait Cat[-T, +U] {
    def meow[W]()
}

It says the position of W is negative.

What does it mean by "negative"? What can I do and what can't do with the type W?

Freewind
  • 193,756
  • 157
  • 432
  • 708
  • 3
    Careful, if you introduce a type parameter T for meow, then it shadows the parameter T of cat. Your code would be just the same, just clearer, if you wrote def meow[U]... – Didier Dupont Apr 29 '14 at 07:40
  • @DidierDupont, thank you, and I remove that samples – Freewind Apr 29 '14 at 07:42
  • Duplicate of http://stackoverflow.com/q/12451702/1296806 That's not a great Q&A, unfortunately. Also, http://stackoverflow.com/q/2723397/1296806 – som-snytt Apr 29 '14 at 11:36

0 Answers0