2014-06-21 108 views
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) 

任何人都可以解釋這裏有什麼問題嗎?

回答

0

我在錯誤仔細地看了看,並把它

implicit def supportedCurrencyToString(currencyEntry: (helpers.SupportedCurrencies.Value, Int)): (String, Int) = currencyEntry._1.toString -> currencyEntry._2 

我需要從配對轉換配對