Scala isEmpty为空集返回false

Scala isEmpty为空集返回false,scala,Scala,在此代码中 def findQuestionCreatedCount(transaction:DistributedTransaction,userId:UUID,tagSet:Set[String]):Future[List[(String,Int)]]={ logger.trace(s"will find questions created portfolio for ${userId} and tagSet ${tagSet}. tagSet empty

在此代码中

    def findQuestionCreatedCount(transaction:DistributedTransaction,userId:UUID,tagSet:Set[String]):Future[List[(String,Int)]]={
        logger.trace(s"will find questions created portfolio for ${userId} and tagSet ${tagSet}. tagSet empty ${tagSet.isEmpty}")
        if(tagSet.isEmpty == false) { //set has data
      ...
}
我看到print
将找到为3455c2b9-37f2-4373-9dcd-9e71b43e8c3d和标记集()创建的问题组合。标记集为空为假


为什么标记集是
Set()
而它的空值是
false
?这不应该是真的吗?

可能在集合中有一个空字符串
,因此在打印时不可见,例如:

scala> Set("").toString
val res0: String = Set()

scala> Set("").isEmpty
val res1: Boolean = false
如果是这样的话,你可以确认一下

tagSet.contains("")

作为一个旁注,请考虑< <代码> > <代码>打印

scala> scala.runtime.ScalaRunTime.stringOf(Set(""))
val res0: String = Set("")
例如,还可以打印周围带引号的字符串

println(Set(""))
pprint.pprintln(Set(""))
println("")
pprint.pprintln("")
输出

Set()
Set("")

""