Funkcja, która ogólnie przyjmuje typ i zwraca ten sam typ

Trudno mi zrozumieć, dlaczego kompilator Scali jest niezadowolony z tej definicji funkcji:

<code>def trimNonWordCharacters[T <: Iterable[String]](items: T): T =
     items map { _.replaceAll("\\W", "") }
</code>

Tutaj jestREPL wydajność:

<code>scala> def trimNonWordCharacters[T <: Iterable[String]](items: T): T =
     items map { _.replaceAll("\\W", "") }
<console>:5: error: type mismatch;
 found   : Iterable[java.lang.String]
 required: T
       def trimNonWordCharacters[T <: Iterable[String]](items: T): T = items map { _.replaceAll("\\W", "") }
</code>

Celem jest przekazanie każdej implementacji Iterable i uzyskanie tego samego typu wycofania. czy to możliwe?

questionAnswers(2)

yourAnswerToTheQuestion