Question

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
                                                        ^
Was it helpful?

Solution

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top