KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I'm new to Scala, and I'm struggling to understand why I sometimes don't get a type error when supplying the wrong argument to Set.contains Here's a quick example using the REPL (2.9.1.final): scala> val baz = Map("one" -> 1, "two" -> 2) baz: scala.collection.immutable.Map[java.lang.String,Int] = Map(one -> 1, two -> 2) scala> baz.values.toSet.contains("asdf") res3: Boolean = false Why didn't I get a type mismatch there? If I assign baz.values.toSet to another val , and call contains on that, I do get type checking: scala> val bling = baz.values.toSet bling: scala.collection.immutable.Set[Int] = Set(1, 2) scala> bling.contains("asdf") <console>:10: error: type mismatch; found : java.lang.String("asdf") required: Int bling.contains("asdf") ^ Stupid mistake, language subtlety, or compiler bug?
Tags (comma-separated)
Save Edits
Cancel