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

Remove double brace initialization #3868

Conversation

marschall
Copy link
Contributor

Remove double brace collection initialization as it is considered bad
practice [1] [2].

However, it is quite obscure, and it costs an extra class at each usage. It also holds hidden references to the enclosing instance and to any captured objects. This may cause memory leaks or problems with serialization. For these reasons, this technique is best avoided.

I think the example of "double-brace initialization" should be even more clearly labeled as pure evil. :-) You could also mention all the horrible consequences if anyone ever serializes such a collection.

[1] https://mail.openjdk.java.net/pipermail/core-libs-dev/2015-September/035441.html
[2] https://openjdk.java.net/jeps/269

Remove double brace collection initialization as it is considered bad
practice.
@fmbenhassine
Copy link
Contributor

Rebased and merged as 3d0cb90. Thank you for your contribution.

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

Successfully merging this pull request may close these issues.

None yet

2 participants