【发布时间】:2017-11-18 02:33:24
【问题描述】:
假设我有以下代码:
object Potato extends App {
type CoolString = String
type AwesomeString = String
def potato(string: String)(implicit coolString: CoolString, awesomeString: AwesomeString) = {
s"$string is a string. Oh, but don't forget - $coolString and also $awesomeString"
}
implicit val ice : CoolString = "Really Cold Ice"
implicit val awe : AwesomeString = "Awe inspiring object"
potato("Stringerino")
}
此代码因问题而失败
[error] ... ambiguous implicit values:
[error] both value ice in object Potato of type => Potato.CoolString
[error] and value awe in object Potato of type => Potato.AwesomeString
[error] match expected type Potato.CoolString
[error] potato("Stringerino")
这样使用隐式是不可能的吗?
【问题讨论】:
标签: scala