扩展集合时,Scala返回类型 [英] Scala return type when extending collection
问题描述
如果我写
class Things扩展了scala.collection.immutable.HashSet [Int]
class Things extends scala.collection.immutable.HashSet[Int]
新事物+ 5
那么结果就是
res0:scala.collection.immutable.HashSet [Int] = Set(5)
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.
推荐答案
没有您的代码样本,我真的无法告诉您,但是您可以看一下Jesse Eichar的帖子,其中提供了实现自定义集合的完整过程并很好地解决了您的问题.
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
这篇关于扩展集合时,Scala返回类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!