Expression of type scala.collection.Set[scala.Predef.String] doesn't conform to expected type scala.Predef.Set[scala.Predef.String] -
i'm relatively new programming , enjoying using scala teach myself. i've come across problem can't seem wrap head around.
here snippet of code i'm trying work on. maps used mutable.map[string, any]
def createcompletevoterset(): set[string] =   {
val firstset = concedevotermap.keyset.diff(votermap.keyset) val secondset = emotevotermap.keyset.diff(votermap.keyset) val thirdset = speedvotermap.keyset.diff(votermap.keyset) var finalset = votermap.keyset ++ firstset ++ secondset ++ thirdset  return finalset   }
the error gives me is: expression of type scala.collection.set[scala.predef.string] doesn't conform expected type scala.predef.set[scala.predef.string]
i'm sure find way force same type, possibly toset(), i'm confused error is. give me insight on why error happening , point me in right direction safe way fix it?
because there no import set, set[string] means scala.predef.set (scala.predef._ imported automatically in scala files). alias scala.collection.immutable.set. keyset method of scala.collection.mutable.map returns scala.collection.set, supertype of scala.collection.immutable.set (and of scala.collection.mutable.set, isn't relevant question). combining scala.collection.sets ++ still gives scala.collection.set. 
the simple solution change return type scala.collection.set, unless require scala.collection.immutable.set other reasons.
Comments
Post a Comment