我有一个id
很长的。但是如果 I getAs[String]
,它会盲目地返回Some(0)
而不是 None。它检查密钥的存在而不是类型。
scala> collection
res26: com.mongodb.DBObject = { "_id" : { "$oid" : "520f8bf544ae41ec63d02eec"} , "date_about" : "2013-08-17T20:13:00.365Z" , "date_created" : "2013-08-17T20:13:00.365Z" , "date_modified" : "2013-09-07T18:03:20.101Z" , "id" : 0 , "node_type" : "meta-folder" , "parent_id" : 0 , "title" : "my stuff, renamed by ajax, wow" , "version" : 2}
scala> collection.getAs[String]("id")
res27: Option[String] = Some(0)
scala> collection.getAs[Long]("id")
res28: Option[Long] = Some(0) //get-ing this is an java.lang.ClassCastException
scala> collection.getAs[Long]("id").get
res29: Long = 0
这不是意外的行为吗?我不应该有Option[String] = None
吗?我如何获得预期的行为?我 sbt-ed "org.mongodb" %% "casbah" % "2.6.2"