小编Den*_*ski的帖子

Scala无实例不= =无

我在Scala代码中遇到了一个间歇性的问题,我正在处理来自带有String键的不可变映射的值.这是基本代码,包括我添加的调试日志:

  val compStruct = subsq.comps get (ident)
  compStruct match {
    ...
    case None =>
      logger.info(s"Found None, of type ${compStruct.getClass.getName}, at position $position (ident $ident)")
      ...
    case x =>
      logger.info(s"Illegal structure of type ${x.getClass.getName} at position $position (ident $ident) - x == None is ${x == None}, x.getClass == None.getClass is ${x.getClass == None.getClass}, x.getClass.getName == None.getClass.getName (${None.getClass.getName}) is ${x.getClass.getName == None.getClass.getName}")
      ...
  }
Run Code Online (Sandbox Code Playgroud)

问题是,当值实际为None时,有时会采用x,如(已消毒的)调试输出所示:

  INFO  ...: Found None, of type scala.None$, at position 3000 (ident XX)
  INFO  ...: Illegal structure …
Run Code Online (Sandbox Code Playgroud)

scala

10
推荐指数
1
解决办法
872
查看次数

标签 统计

scala ×1