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

Default values and staged builders #187

Open
CfFanDuel opened this issue Aug 15, 2024 · 0 comments
Open

Default values and staged builders #187

CfFanDuel opened this issue Aug 15, 2024 · 0 comments

Comments

@CfFanDuel
Copy link

Staged builders are useful to force compile time safety that all required attributes are set. The autocomplete they give is lovely too.

If any components are marked as nullable then they are optional.

The same isn't true for components marked with a default value. You're forced to specify a value. This is wrong I feel.

Sample code to see:

@MyStagedRecordBuilder
public record Person(
        @Initializer("DEFAULT_NAME") String name,
        @Nullable int age,
        String somethingElse
) {

    public static final String DEFAULT_NAME = "John Doe";

    void test() {
        var x = PersonBuilder.staged()
                .name("ds")
                .somethingElse("aada")
                .age(21);
    }
}

In this instance as name has a default value the only component I should be forced to specify is somethingElse, but i'm forced to specify name.

I'm conscious at this point this is trying to turn the library into a replacement for named and default arguments found in other languages. But seeing as both of these pieces of functionality are available I thought it worth raising :)

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

1 participant