Skip to content

FR: correctly handle constructor-injection for records #5166

@chris-gray-aem

Description

@chris-gray-aem

In #4344 @bcorso says

you may run into issues trying to use constructor injection with a record class (which probably doesn't make sense anyway, but just as an example).

I think it does make sense and would reduce some boilerplate.

For example, if you have

public class FooService {
  private final FooRepository fooRepository;

  @Inject
  public FooService(FooRepository fooRepository) {
    this.fooRepository = fooRepository;
  }
}

that's way more verbose than

public record FooService(FooRepository fooRepository) {
  @Inject
  public FooService {}
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions