Note that there are some explanatory texts on larger screens.

plurals
  1. POWeird Type Mismatch in Scala
    primarykey
    data
    text
    <p>I hope this question hasn't been answered yet somewhere else. Didn't find an answer here.</p> <p>In my localisation system I've got a class named Language</p> <pre><code>class Language(val name:String, dict:HashMap[String, String]) { def apply(key: String):String = (dict get key) match { case None =&gt; "°unknown°" case Some(s) =&gt; s } //DO SOME OTHER THINGS } </code></pre> <p>and an object named LanguageCentral</p> <pre><code>object LanguageCentral { private var lang:Option[Language] = None //SOME OTHER PRIVATE MEMBERS def language = lang def language_=(l:Option[Language]) = l match { case None =&gt; {} case Some(l) =&gt; setLanguage(l) } def setLanguage(l:Language) { lang = Some(l) //DO SOME OTHER THINGS } //DO LOTS OF OTHER THINGS } </code></pre> <p>I haven't written any code that's using this framework yet but trying it in an interactive session revealed a type error I don't really understand:</p> <pre><code>scala&gt; val l = new LanguageCreator("Languages.csv").getLanguage("English") l: Option[Language] = Some(Language@7aeb46d) scala&gt; LanguageCentral.language=l &lt;console&gt;:23: error: type mismatch; found : Option[Language] required: Option[Language] LanguageCentral.language=l ^ scala&gt; LanguageCentral setLanguage (l getOrElse null) &lt;console&gt;:24: error: type mismatch; found : Language required: Language LanguageCentral setLanguage (l getOrElse null) ^ </code></pre> <p>I really don't have a clue what's wrong. But from my experience with Haskell I guess that the solution is only a minor change away.;)<br> Could somebody help me? Thx.</p> <p>P.S.: using Scala 2.8.0.final</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload