whe*_*ies 4 scala implicit implicit-typing implicit-conversion
我编写了一个扩展Iterator [A]的自定义特性,我希望能够使用我在另一个方法返回的迭代器[A]上编写的方法.这可能吗?
trait Increment[+A] extends Iterator[A]{
def foo() = "something"
}
class Bar( source:BufferedSource){
//this ain't working
def getContents():Increment[+A] = source getLines
}
Run Code Online (Sandbox Code Playgroud)
我仍然试图绕过整个隐含的东西而不是在Bar对象定义中编写方法.我将如何以上述方式包装这样的物品?
弄清楚了.我尝试了解一下:
object Increment{
implicit def convert( input:Iterator[String] ) = new Increment{
def next() = input next
def hasNext() = input hasNext
}
}
Run Code Online (Sandbox Code Playgroud)
我已经完成了 太奇怪了.
| 归档时间: |
|
| 查看次数: |
815 次 |
| 最近记录: |