eclipse-jdt / eclipse-jdt/eclipse.jdt.core

Problem with calling super in overridden default method

Open
#1,600 36 comments 2 reactions 2 assignees Claimed by @srikanth-sankaran View on GitHub
bug compiler
Dominant language
Java
Stars
237
Forks
195
Avg merge
1d 12h
Merged PRs (30d)
47

Description

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.

```java
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)
{
}
}
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.