support Implementing interfaces with covariant return types
Open
Nobody has claimed this yet.
- Dominant language
- Kotlin
- Stars
- 217
- Forks
- 116
- PR merge metrics
- No merged PRs in 30d
Description
This is to support implementing an interface by allowing an implementing field to return a subtype of the interface field's return type.
interface Friendly {
bestFriend: Friendly
}
type Person implements Friendly {
bestFriend: Person
}
// Generated java interface
@JsonTypeInfo(
use = JsonTypeInfo.Id.NAME,
include = JsonTypeInfo.As.PROPERTY,
property = "__typename"
)
@JsonSubTypes(@JsonSubTypes.Type(value = Person.class, name = "Person"))
public interface Friendly {
Friendly getBestFriend();
void setBestFriend(Friendly bestFriend);
}
// generated java class
public class Person implements Friendly {
private Person bestFriend;
public Person getBestFriend() {
return bestFriend;
}
public void setBestFriend(Person bestFriend) {
this.bestFriend = bestFriend;
}
The generated java code doesn't compile, as the class needs to implement the setter with "interface" parameter definition like that:
public void setBestFriend(Friendly bestFriend) {
this.bestFriend = bestFriend;
}
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by locating the Java interface and implementing-class generation logic for fields such as bestFriend, then inspect the related generator tests if present. Done means the generated Person class compiles while implementing Friendly, including compatible getter and setter signatures for the subtype return and interface parameter.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, kotlin
- Domain
- tooling
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100