scala - 上面类的访问方法

标签 scala

如何在B类中使用A类的isEmpty?

Class A{
  def isEmpty = ...

  Class B{
    def isEmpty = ...
  }

}

最佳答案

试试这个:

class A {
  outer =>

  def isEmpty = ...
  class B {
    def isEmpty = outer.isEmpty
  }
}

或者:

class A {
  def isEmpty = ...
  class B {
    def isEmpty = A.this.isEmpty
  }
}

关于scala - 上面类的访问方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6641608/

相关文章:

scala - 有人可以解释为什么在 Scala 中应用这样的 map 会抛出和 IllegalArgumentException 吗?

scala - 将Spark Scala App的同一数据框中的“天数”列添加到“日期”列

java - 用于Scala开发的java8中的gradle REPL

Scala条件列表构造

scala - 在 Apache Spark 中的 groupBy 之后聚合 Map 中的所有列值

Scala View 应用程序谜题

scala - 复制 Spark Row N 次

scala:无法检查匹配是否无法访问

scala持续时间: "This class is not meant as a general purpose representation of time, it is optimized for the needs of scala.concurrent."

scala - 尝试将 F 有界多态性建模为 Scala 中的类型成员