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

avoid unnecessary ArrayList creations; use Collections.singletonList … #906

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

ispringer
Copy link

…rather than Arrays.asList where possible

…rather than Arrays.asList where possible

Signed-off-by: Ian Springer <[email protected]>
Copy link
Member

@fstab fstab left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot for the PR! To be honest, I find immutability in Java really hard. For example, take the following code:

String[] excludedName = new String[1];

excludedName[0] = "some name";
ExporterFilterProperties filter1 = ExporterFilterProperties.builder().excludedNames(excludedName).build();

excludedName[0] = "some other name";
ExporterFilterProperties filter2 = ExporterFilterProperties.builder().excludedNames(excludedName).build();

To be fair, it's a contrived example.

However, if we don't copy the array then filter1 will be altered after it was created, so it won't be immutable.

I don't see a good way to avoid this other than creating copies of the arrays.

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

Successfully merging this pull request may close these issues.

None yet

2 participants