0
我定義枚舉隱式轉換和映射關鍵
object SupportedCurrencies extends Enumeration {
type SupportedCurrencies = Value
val USD, GBP, ARS, AUD, BRL, CAD, CHF, CNY, EUR, JPY, SEK, DKK, NOK = Value
}
和隱式轉換爲它的字符串
implicit def supportedCurrencyToString(currency: SupportedCurrencies.Value): String = currency.toString
,但如果我將嘗試創建一個地圖[字符串, Int]
val m: Map[String, Int] = Map(USD -> 1)
我是出現錯誤
type mismatch;
[error] found : (helpers.SupportedCurrencies.Value, Int)
[error] required: (String, Int)
[error] val m: Map[String, Int] = Map(USD -> 1)
任何人都可以解釋這裏有什麼問題嗎?