scala, guidelines on return type - when prefer seq, iterable, traversable

后端 未结 5 1197
天命终不由人
天命终不由人 2021-01-31 07:44

When do you choose to type a given function\'s return type as Seq vs Iterable vs Traversable (or alternatively even deeper within Se

5条回答
  •  独厮守ぢ
    2021-01-31 07:51

    Make your method's return type as specific as possible. Then if the caller wants to keep it as a SuperSpecializedHashMap or type it as a GenTraversableOnce, they can. This is why the compiler infers the most specific type by default.

提交回复
热议问题