Skip to content

Problem with calling super in overridden default method #1600

@Frettman

Description

@Frettman

This problem is probably easiest to describe using the following standalone code. It's cut down as much as possible from a real world example. Basically I'm trying to extend a class and override a method whose implementation has been provided as default method in an interface somewhere in the hierarchy. Trying to call the overridden method via super fails with Cannot directly invoke the abstract method setReadOnly(boolean) for the type HasValue.

The same code compiles fine with OpenJDK 17.

public class TestField
  extends
    CustomField
{
  @Override
  public void setReadOnly(boolean readOnly)
  {
    // Eclipse shows this compile error: Cannot directly invoke the abstract method setReadOnly(boolean) for the type HasValue
    super.setReadOnly(readOnly);
  }
}

abstract class CustomField
  extends
    AbstractField
  implements
    HasValue
{
}

abstract class AbstractField
  implements
    HasValueAndElement
{
}

interface HasValue
{
  void setReadOnly(boolean readOnly);
}

interface HasValueAndElement
  extends
    HasValue
{
  @Override
  default void setReadOnly(boolean readOnly)
  {
  }
}

Metadata

Metadata

Labels

bugSomething isn't workingcompilerEclipse Java Compiler (ecj) related issues

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions