Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/extjs/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Scala 无法制作内部对象';s外部专用的方法_Scala_Private Members - Fatal编程技术网

Scala 无法制作内部对象';s外部专用的方法

Scala 无法制作内部对象';s外部专用的方法,scala,private-members,Scala,Private Members,在以下示例中,我无法隐藏update,不让公众曝光: trait Order { sealed trait EntryOption { private[Order] def update(e: EntryOption): Unit } private case object EmptyEntry extends EntryOption { def update(e: EntryOption) = () } trait Entry extends Entry

在以下示例中,我无法隐藏
update
,不让公众曝光:

trait Order {
  sealed trait EntryOption {
    private[Order] def update(e: EntryOption): Unit
  }

  private case object EmptyEntry extends EntryOption {
    def update(e: EntryOption) = ()
  }

  trait Entry extends EntryOption

  def test(a: Entry, b: EntryOption): Unit = a.update(b)
}
它无法使用
“错误:无法创建对象,因为没有定义类型(e:Order.this.EntryOption)单元的trait EntryOption中的方法$line12$$read$Order$^date”
”–不管应该是什么(编译器错误?)。我尝试了以下方法,但没有成功:

  • EmptyEntry
    private[Order]
  • 使其受到保护–这会中断方法测试
目标是让
EntryOption
update
从外部
订单
无法访问

编辑

如果我暂时将
trait-Order
更改为
object-Order
,它将编译,这表明存在潜在的编译器错误?

一个愚蠢的解决方法:

trait Order {
  sealed trait EntryOption {
    private[Order] def update(e: EntryOption): Unit
  }

  private sealed trait ScalaChokes extends EntryOption {
    private[Order] final def update(e: EntryOption) = ()
  }

  private case object EmptyEntry extends ScalaChokes

  trait Entry extends EntryOption
}

我应该提交一个bug吗?

EntryOption中的更新应该被保护而不是私有吗?@david然后方法
test
无法访问它