我想在父类的父级上调用一个方法。我几乎可以肯定这是可能的,但是下面会产生错误:
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
}
编译器说AbstractUndoableEdit
不是CompoundEdit
的父类(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 :(得分:4)
这是不可能的。原因是,它会违反封装。
请参阅why is super.super not allowed in java和similar question for scala