开发者

Scala return type when extending collection

开发者 https://www.devze.com 2023-01-27 04:42 出处:网络
If I write class Things extends scala.colle开发者_如何学Pythonction.immutable.HashSet[Int] new Things + 5

If I write

class Things extends scala.colle开发者_如何学Pythonction.immutable.HashSet[Int]

new Things + 5

Then the result is

res0: scala.collection.immutable.HashSet[Int] = Set(5)

What do I need to do for the result to be of type Things? I suspect the answer might be here, but am struggling to understand what's going on.


I can't really tell without a sample of your code but you can take a look at Jesse Eichar's post which provides a walk through the implementation of a custom collection and addresses your question nicely.

http://daily-scala.blogspot.com/2010/04/creating-custom-traversable.html

0

精彩评论

暂无评论...
验证码 换一张
取 消