【发布时间】:2014-10-24 10:38:15
【问题描述】:
让
def h(a: AnyRef*) = a.mkString(",")
h: (a: AnyRef*)String
等等
h("1","2")
res: String = 1,2
但是,h(1,2)
error: the result type of an implicit conversion must be more specific than AnyRef
h(1,2)
^
error: the result type of an implicit conversion must be more specific than AnyRef
h(1,2)
^
至少在 Scala 2.11.1 和 2.11.1 中是这样。 询问解决方法。
【问题讨论】:
-
scala 2.10.X 上的 scala repl 给出了更有意义的响应:
error: type mismatch; found : Int(1) required: AnyRef Note: an implicit exists from scala.Int => java.lang.Integer, but methods inherited from Object are rendered ambiguous. This is to avoid a blanket implicit which would convert any scala.Int to any AnyRef. You may wish to use a type ascription:x: java.lang.Integer. h(1,2) -
顺便用
val x: AnyRef = 42复现问题
标签: scala