What's the difference between these two calls to a function taking a collection of structural types?

Posted by James Moore on Stack Overflow See other posts from Stack Overflow or by James Moore
Published on 2010-05-16T20:18:05Z Indexed on 2010/05/16 20:20 UTC
Read the original article Hit count: 228

Filed under:
|

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?

© Stack Overflow or respective owner

Related posts about scala

Related posts about scala-2.8