0__
0__

Reputation: 67300

Accessing a method in a super super class

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
                                                        ^

Upvotes: 0

Views: 83

Answers (1)

lpiepiora
lpiepiora

Reputation: 13749

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

Upvotes: 4

Related Questions