Bug 322497 - add code style problem for invocation of varargs method with unnecessary "new Type[] {..}"
Summary: add code style problem for invocation of varargs method with unnecessary "new...
Status: NEW
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.7   Edit
Hardware: PC Windows XP
: P3 enhancement (vote)
Target Milestone: ---   Edit
Assignee: JDT-Core-Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-08-12 05:57 EDT by Markus Keller CLA
Modified: 2019-07-29 13:13 EDT (History)
3 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Markus Keller CLA 2010-08-12 05:57:59 EDT
HEAD

We could add a code style problem for an invocation of a varargs method with unnecessary "new Type[] {..}" right in the arguments list.

Example:
public class Try {
    public static void main(String[] args) {
        foo("x", "1", "1");
        foo("x", 1);
        foo("x", "a", "b");
        
        // add a problem for these two:
        foo("x", new String[] {"a"});
        foo("x", new Object[] {"a", "b"});
    }
    
    static void foo(String first, Object... o) {
        System.out.println(o.getClass());
    }
}

JDT/UI can then add a quick fix to remove the unnecessary explicit array creation. The quick fix should also work in the 'new String[] {"a"}' case in the example, although there's another problem reported there.