Type parameter, collection and return type

3 replies

Thu, 2012-02-09, 17:55

Ka Ter

Joined: 2011-10-05,

Hi,

why is the following code producing the compiler error 'type mismatch;
found : Traversable[Any] required: C'? The type of the collection
doesn't change and therefore it is a C. If I ommit the ':C' of the
method than the return type is inferred to Traversable[Any].

Because C might be a supertype of Traversable[Any], but filter will return a Traversable[Any]. Look at the filter signature on scala collections.

Best RegardsEdmondo Porcu

2012/2/9 Ka Ter <ter [dot] ka966 [at] googlemail [dot] com>

Hi,

why is the following code producing the compiler error 'type mismatch;
found : Traversable[Any] required: C'? The type of the collection
doesn't change and therefore it is a C. If I ommit the ':C' of the
method than the return type is inferred to Traversable[Any].