Skip to content

Is It Possible to Provide an Interface for the ...Builder.With Interface to Extend? #257

@adrian-tavve

Description

@adrian-tavve

I don't believe this is the same ask as #211

I have a base interface for a group of record classes. One of the things this accomplishes is providing a type for specific with*() methods that should be common to every subclass:

interface CommonWithers {

  public CommonWithers withId(int id);
}

@RecordBuilder
record Foo(int id, Foo foo) implements CommonWithers, FooBuilder.With {}

However, this doesn't compile. The FooBuilder.With.withId(int) method doesn't satisfy the CommonWithers.withId(int) requirement - even though copy+pasting that generated method into Foo does satisfy it.

What I'm looking for is a way to make FooBuilder.With extend CommonWithers, so its default method can satisfy the interface. Something similar to:

@RecordBuilder
@RecordBuilder.Options( withExtendsInterface = CommonWithers.class )
record Foo(int id, Foo foo) implements FooBuilder.With {}

which would generate a With interface like

public class FooBuilder {

  //  . . .

  public interface With extends CommonWithers {

    default Foo withId(int id) {
      //  . . .

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions