openrewrite / openrewrite/rewrite
Marker::withId type param should probably be defined at the interface level
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 3.7k
- Forks
- 570
- Avg merge
- 13h 12m
- Merged PRs (30d)
- 261
Description
And, try to write a class implementing this interface without using Lombok for the withId implementation.
It might look like this:
class MyMarker implements Marker {
@Override
public UUID getId() {
return UUID.randomUUID();
}
@Override
public MyMarker withId(final UUID id) {
return new MyMarker();
}
}
...which has an unchecked conversion warning on the withId return type, because it's not M. Using Lombok to generate the method covers that up, but if you're writing a custom Marker without Lombok, you're stuck with warnings.
It looks like when you define an interface method which declares a type param, then the use of generics becomes part of the method signature which subclasses must fulfill, and a class implementing the interface cannot specify the type param.
Instead, if we do public interface Marker<M extends Marker<M>>, then the signature of withId works as expected. But, this change would require a touch to ~every Marker implementation (to specify that type param at the class declaration), which might be disruptive.
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 with rewrite-core/src/main/java/org/openrewrite/marker/Marker.java at the referenced interface definition, then inspect the Marker implementations that would need a type parameter. Reproduce the unchecked conversion with the custom implementation shown in the issue, and assess the interface change's impact before deciding whether it is viable. Done means the chosen API has no warning for custom implementations and affected code still compiles.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- backend-api-design
- Issue type
- Refactor
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 30/100