2014-06-21 2 views
0

I définis ENUMconversion implicite et carte clé

object SupportedCurrencies extends Enumeration { 
type SupportedCurrencies = Value 

val USD, GBP, ARS, AUD, BRL, CAD, CHF, CNY, EUR, JPY, SEK, DKK, NOK = Value 

}

et conversion implicite à chaîne

implicit def supportedCurrencyToString(currency: SupportedCurrencies.Value): String = currency.toString 

mais si je vais essayer de créer une carte [String, Int]

val m: Map[String, Int] = Map(USD -> 1) 

Je suis obtenir une erreur

type mismatch; 
[error] found : (helpers.SupportedCurrencies.Value, Int) 
[error] required: (String, Int) 
[error]   val m: Map[String, Int] = Map(USD -> 1) 

Quelqu'un pourrait-il expliquer ce qui ne va pas ici?

Répondre

0

Je regardai attentivement l'erreur et l'obtenir

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

je besoin d'une conversion de paire à