2011-09-19 45 views

回答

22

有一个在scala.Predef对象的隐式转换:

implicit def any2stringadd(x: Any): StringAdd 

StringAdd限定+操作者/方法:

def +(other: String) = String.valueOf(self) + other 

此外,由于scala.Predef始终处于范围内,因此该隐式转换将始终有效。

+4

'StringAdd'住在'scala.runtime'([Github上的源代码](https://github.com/scala/scala/blob/master/src/library/scala/runtime/StringAdd.scala)) 。我不确定它为什么不出现在[ScalaDoc](http://www.scala-lang.org/api/current/index.html#scala.runtime.package)中。 –

+0

感谢您的链接 - 我已将它添加到我的回答中 – Dylan

+0

@Kipton Interresting“not in scaladoc”,有没有其他特征/对象不在scaladoc中? (一个人假设在scaladoc中找到每个scala特质/对象)对我来说似乎值得一个新的SO问题... –

相关问题