xyz
xyz

Reputation: 65

Access method of class above

How can I use the isEmpty of class A in Class B?

Class A{
  def isEmpty = ...

  Class B{
    def isEmpty = ...
  }

}

Upvotes: 2

Views: 160

Answers (1)

Jean-Philippe Pellet
Jean-Philippe Pellet

Reputation: 60006

Try this:

class A {
  outer =>

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

Alternatively:

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

Upvotes: 7

Related Questions