Scala - 如何调用内部类方法?

时间:2018-04-29 01:36:22

标签: scala class methods

我有一个scala文件跟在类之后(以及主流方法):

class OuterClass {
  class Inner {

    def innerMethod(): Unit = {
      println("innerMethod")
    }

    class InnerMost {
      innerMethod()
    }
  }
}

现在想从main方法调用该类:

  object main {
    def main (args: Array[String] ): Unit = {
          println("Main")
          val pt = new OuterClass
          ...
      }
  }

如何实现?

1 个答案:

答案 0 :(得分:3)

要实例化嵌套类Inner,然后InnerMost

val pti = new pt.Inner
val ptim = new pti.InnerMost