Intention idea
I run into code like this from time to time:
List ints = Arrays.asList(new Integer[] {1, 2, 3});
The intention was to staticly create a list as cleanly as possible. I think this code looks a little cleaner:
List]]> ints = Arrays.asList(1, 2, 3);
Is there an existing inspection or an add-on intention for this?
Please sign in to leave a comment.
Hello Bryan,
BY> I run into code like this from time to time:
BY> List ints = Arrays.asList(new Integer[] {1, 2, 3}); BY> The intention was to staticly create a list as cleanly as possible. BY> I think this code looks a little cleaner: BY> BY> List ints = Arrays.asList(1, 2, 3); BY> BY>]]> Is there an existing inspection or an add-on intention for this?
"Redundant array creation"
--
Dmitry Jemerov
Software Developer
JetBrains, Inc.
http://www.jetbrains.com/
"Develop with Pleasure!"
Strange. I just ran into some code that had "Redundant array creation" highlighted. I pasted my example into that code, but it wasn't highlighted. I think its because Arrays.asList() takes a generic type as its parameter.
In this example, the first line is highlighted, but the second is not:
List ints1 = asList2(new Integer[] {1, 2, 3}); List ints2 = Arrays.asList(new Integer[] {1, 2, 3}); Here's the code for asList2: public static List]]> asList2(Integer... a) {
return Arrays.asList(a);
}
Is this a bug?
Unless I'm misunderstanding something about generics, this should be considered a bug. I submitted a JIRA request: IDEA-10639.