Char
不是的子类型
ScalaObject
.
在你的顶端
Any
什么都是超级的。你可能可以替换
缩放对象
具有
任何
这将使您的代码能够编译。
见
http://www.scala-lang.org/node/128
对于类型层次结构图。
在repl中,可以使用隐式函数对类型关系进行故障排除:
scala> implicitly[Char <:< Any]
res0: <:<[Char,Any] = <function1>
scala> implicitly[Char <:< ScalaObject]
<console>:6: error: could not find implicit value for parameter e: <:<[Char,ScalaObject]
implicitly[Char <:< ScalaObject]
^
scala> implicitly[List[Char] <:< List[Any]]
res2: <:<[List[Char],List[Any]] = <function1>
scala> implicitly[List[Char] <:< List[ScalaObject]]
<console>:6: error: could not find implicit value for parameter e: <:<[List[Char],List[ScalaObject]]
implicitly[List[Char] <:< List[ScalaObject]]
编辑:顺便问一下,你知道吗
mkString
?
trans(s).mkString("[", ", ", "]")