-
Notifications
You must be signed in to change notification settings - Fork 742
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
Detect collections using double brace initialization #914
Labels
Comments
Or suggest Set.of, List.of, or Map.of in about 45 days when Java 10 is out.
…On Sat, Jan 27, 2018, 9:46 PM Andrew Gaul ***@***.***> wrote:
Some call sites construct collections via double brace initialization:
new HashSet<String>() {{ add("NU"); add("TK"); add("NC"); add("AC"); }};
error-prone should recommend the more succinct and efficient:
new HashSet<String>(Arrays.asList("NU", "TK", "NC", "AC"));
The former creates an anonymous inner class and an implicit this reference
which can prolong the outer class lifetime:
https://blog.nishtahir.com/2015/09/27/why-you-shouldnt-use-the-double-brace-initializer/
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#914>, or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAEEEYTmsaMpKsq7VLoxgksGUgWLSNQHks5tO9-WgaJpZM4RvinU>
.
|
Oops that's in Java 9!
…On Sat, Jan 27, 2018, 9:50 PM Jake Wharton ***@***.***> wrote:
Or suggest Set.of, List.of, or Map.of in about 45 days when Java 10 is out.
On Sat, Jan 27, 2018, 9:46 PM Andrew Gaul ***@***.***>
wrote:
> Some call sites construct collections via double brace initialization:
>
> new HashSet<String>() {{ add("NU"); add("TK"); add("NC"); add("AC"); }};
>
> error-prone should recommend the more succinct and efficient:
>
> new HashSet<String>(Arrays.asList("NU", "TK", "NC", "AC"));
>
> The former creates an anonymous inner class and an implicit this
> reference which can prolong the outer class lifetime:
>
>
> https://blog.nishtahir.com/2015/09/27/why-you-shouldnt-use-the-double-brace-initializer/
>
> —
> You are receiving this because you are subscribed to this thread.
> Reply to this email directly, view it on GitHub
> <#914>, or mute the thread
> <https://github.com/notifications/unsubscribe-auth/AAEEEYTmsaMpKsq7VLoxgksGUgWLSNQHks5tO9-WgaJpZM4RvinU>
> .
>
|
Or even Guava's |
ronshapiro
pushed a commit
that referenced
this issue
Feb 5, 2018
Fixes #914 RELNOTES: N/A ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=184371199
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Some call sites construct collections via double brace initialization:
error-prone should recommend the more succinct and efficient:
The former creates an anonymous inner class and an implicit this reference which can prolong the outer class lifetime:
https://blog.nishtahir.com/2015/09/27/why-you-shouldnt-use-the-double-brace-initializer/
The text was updated successfully, but these errors were encountered: