Skip to content

Prefer inherited class methods over interface declarations - #140

Open
fly1d wants to merge 2 commits into
FasterXML:mainfrom
fly1d:fix/inherited-method-return
Open

fly1d wants to merge 2 commits 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.

@cowtowncoder cowtowncoder added the cla-needed PR looks good (although may also require code review), but CLA needed from submitter label Nov 26, 2026
@cowtowncoder

Copy link
Copy Markdown
Member

Sounds good. Before merging, we'd need CLA from:

https://github.com/FasterXML/jackson/blob/main/CLA-jackson-pre-2026.pdf

(name refers to Jackson but CLA version itself does not)

The usual way is to print it, fill & sign, scan/photo, email to cla at fasterxml dot com.

@github-actions

Copy link
Copy Markdown

🧪 Code Coverage Report

Metric Coverage Change
Instructions coverage 96.05% 📈 +0.710%
Branches branches 90.41% 📈 +0.940%

Coverage data generated from JaCoCo test results

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

Labels

cla-needed PR looks good (although may also require code review), but CLA needed from submitter

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Unintuitive information about member methods wrt return type covariance

2 participants