Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"cannot implement" interface error when using delegating java.util.List via @link in JDK 21 #489

Closed
rsmckinney opened this issue Sep 8, 2023 · 1 comment
Labels

Comments

@rsmckinney
Copy link
Member

The following class will cause a compile error: "MyList cannot implement reversed()..."

public class MyList<E> implements List<E> {
  @link List<E> l = new ArrayList<>();
}

Note, error is nondeterministic. It happens maybe every other build.

After some digging, the error is a result of how delegation classes are generated wrt implementing interfaces. The order of the interfaces that are implemented is nondeterministic from build to build because javac Type classes don't override hashcode, so it's based on default hashcode. But the real problem is that delegation code does not take into account covariant return types in some cases, which can lead to "cannot implement" compile errors.

@rsmckinney rsmckinney added the bug label Sep 8, 2023
rsmckinney added a commit that referenced this issue Sep 8, 2023
- sort interfaces to prevent implementing a super-interface method instead of the sub-interface override with a more specific covariant return
@rsmckinney
Copy link
Member Author

Fixed with release 2023.1.23

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant