質問

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
                                                        ^
役に立ちましたか?

解決

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

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top