What's the difference between these two calls to a function taking a collection of structural types?
- by James Moore
Why does the call to fn(Iterator("foo") compile, but the call to fn(fooIterator) fail with an error "type mismatch; found : Iterator[java.lang.String] required: scala.Iterator[com.banshee.Qx.HasLength]"
object Qx {
type HasLength = {def length: Int}
def fn(xs: Iterator[HasLength]) = 3
var tn = fn(Iterator("foo"))
var fooIterator = Iterator("foo")
var tnFails = fn(fooIterator) //doesn't compile
}
Aren't they the same thing?