0

I want to invoke a method on the parent of a parent class. I am almost certain this is possible, but the following produces an error:

import javax.swing.undo._

def test(name: String): CompoundEdit = new CompoundEdit {
  override def getPresentationName    : String = name

  override def getUndoPresentationName: String = 
    super[AbstractUndoableEdit].getUndoPresentationName

  override def getRedoPresentationName: String = 
    super[AbstractUndoableEdit].getRedoPresentationName
}

The compiler says AbstractUndoableEdit is not a parent class of CompoundEdit (which is wrong):

<console>:55: error: AbstractUndoableEdit does not name a parent class of <$anon: javax.swing.undo.CompoundEdit>
         override def getUndoPresentationName: String = super[AbstractUndoableEdit].getUndoPresentationName
                                                        ^
<console>:56: error: AbstractUndoableEdit does not name a parent class of <$anon: javax.swing.undo.CompoundEdit>
         override def getRedoPresentationName: String = super[AbstractUndoableEdit].getRedoPresentationName
                                                        ^
0__
  • 66,707
  • 21
  • 171
  • 266
  • Actually I think it is not possible. See the answer to this question http://stackoverflow.com/questions/8028627/select-certain-super-class-for-method-call-in-scala – lpiepiora May 11 '14 at 21:32
  • @lpiepiora thanks for the link; that's unfortunate; can you post that as an answer, anyways – 0__ May 11 '14 at 21:33

1 Answers1

4

This is not possible. The reason for that is, that it would violate encapsulation.

See why is super.super not allowed in java and similar question for scala

Community
  • 1
  • 1
lpiepiora
  • 13,659
  • 1
  • 35
  • 47