Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature: constructor method that returns builder #1498

Open
caleb-cushing0-kr opened this issue Dec 4, 2023 · 1 comment
Open

feature: constructor method that returns builder #1498

caleb-cushing0-kr opened this issue Dec 4, 2023 · 1 comment

Comments

@caleb-cushing0-kr
Copy link

caleb-cushing0-kr commented Dec 4, 2023

@Value.Immutable
public interface FindCustomerCommand {

    @Value.Parameter
    String getCorrelationId();

    @Nullable
    String getFieldsGroups();

I'd love to have have a @Value.Style setting that allows me to have the constructor return the builder, so that I can have required parameters set by the constructor.

ImmutableFindCustomerCommand.of("correlationId").fieldGroups("...").build();

I know this is similar to staged, but when it's only one or two parameters, that seems kind of overkill.

@elucash
Copy link
Member

elucash commented Feb 18, 2024

@Style(allMandatoryParameters=true) can help you, but in for such cases / and overall small amount of fields we just stick to using with-methods. If you copy object (shallowly) couple of times in the close lines of code, with high chances of escape-analysis eliminating some allocations, it may be as efficient as builder.

ImmutableFindCustomerCommand.of("correlationId").withFieldGroups("...");

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants