Skip to content

Prefer inherited class methods over interface declarations - #140

Open
fly1d wants to merge 1 commit into
FasterXML:mainfrom
fly1d:fix/inherited-method-return
Open

fly1d wants to merge 1 commit into
FasterXML:mainfrom
fly1d:fix/inherited-method-return

Conversation

@fly1d

@fly1d fly1d commented Oct 29, 2026

Copy link
Copy Markdown

For C extends B implements A, member resolution can select A's method even when B supplies an implementation with a narrower return type. For example, an interface returning Foo hides an inherited method returning the subtype Bar.

Prefer a public class declaration over an earlier interface declaration with the same method key. Resolve its return and argument types in the class's generic context, while retaining the existing hierarchy order and inheritable annotation priority. Direct annotations and mix-in overrides are applied to the selected declaration.

Fixes #57.

Added 18 tests covering covariant and generic returns, direct overrides, default and abstract methods, filtering, and method/parameter annotations. The same tests give 13 failures and 5 passing controls on the original code, then all pass with the fix.

./mvnw clean verify passes on OpenJDK 17.0.20 with the wrapper's Maven 3.9.11: 375 tests, no failures, errors or skips. This includes packaging, module metadata, coverage and Javadoc generation; the POM and Java 8 source/target settings are unchanged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Unintuitive information about member methods wrt return type covariance

1 participant