tags:

views:

121

answers:

2

Using scala, 2.8:

import scala.collection.mutable
import mutable.MultiMap
val m = new mutable.HashMap[String, mutable.Set[String]] with MultiMap[String, String]
m.addBinding("key", null)
m exists { _._2 contains null }

prints false

m exists { _._2 isEmpty }

prints false

m("key").size

prints 1

How do I find the first key (or any) key that was added via an addBinding call with a value of null?

+3  A: 

Perhaps this is a bug, but it is what I observe in Scala 2.8.RC3:

scala> import scala.collection.mutable.HashSet
import scala.collection.mutable.HashSet

scala> val hs1 = new HashSet[String]
hs1: scala.collection.mutable.HashSet[String] = Set()

scala> hs1 += null
res0: hs1.type = Set()

scala> hs1.size
res1: Int = 1

scala> hs1.contains(null)
res2: Boolean = false
Randall Schulz
+4  A: 
Arjan Blokzijl