/**
* Testing Arrays
* @author N002213F
* @version 1.0
*/
public class JavaArrays {
public void processNames(String[] arg) {
//-- patented method, stop, do not read ;)
}
public void test() {
// works fine
String[] names1 = new String[] { "Jane", "John" };
processNames(names1);
// works fine, nothing here
String[] names2 = { "Jane", "John" };
processNames(names2);
// works again, please procced
processNames(new String[] { "Jane", "John" });
// fails, why, are there any reasons?
processNames({ "Jane", "John" });
// fails, but i thought Java 5 [vargs][1] handles this
processNames("Jane", "John");
}
}
/** * Testing Arrays * @author N002213F * @version 1.0 */ public class JavaArrays
Share
You didn’t specify a type. Java doesn’t do type inference here; it expects you to specify that this is a string array. The answers to this question may help for this, too
If you want varargs, then you should write your method as such:
Note the
...instead of[]. Just accepting an array doesn’t entitle you to use varargs on that method.