Weird compile error involving type parameters with a wildcard

Viewed 76

I am sorry, I can't formulate the title (or the question for that matter) to be any more informative than this, because I have no idea what is going on here. Why doesn't this code compile:

 class Foo
 class Bar[+R <: Foo] { def bar = "bar" }
 class Bak(val b: Bar[_])
 val bak = new Bak(new Bar[Foo])
 bak.b.bar // fine
 println(bak.b) // fine
 bak.b  // oops!
 ^^^ type arguments [Any] do not conform to class Bar's type parameter bounds [+R <: Foo]

What is this? Why can I use the variable, but not assign it it a val??? Does it make sense to anyone?

1 Answers
Related