public void dummyMethod(String... arrs) {
// do something
// arrs is an array (String[]) internally
System.out.println(arrs[0]);
}
dummyMethod("anystring1", "anystring2", "anystring3"); //this will work fine
// OR this will work fine too
dummyMethod(new String[]{ "anystring1", "anystring2", "anystring3" });
// OR without passing any args . this will also work fine..
dummyMethod();
見相差太大編譯這些之後...我只是把這樣一個例子。我剛纔也提到的評論只是看到不同的自己......
public void dummyMethod(String[] arr1) {
System.out.println(arr1[0]);
}
// this method will work correctly
dummyMethod(new String[]{ "anystring1", "anystring2", "anystring2" });
// but type of calling Raise an compilation error!!!
dummyMethod("anystring1", "anystring2", "anystring3");
請參考這個鏈接的說明。 http://stackoverflow.com/questions/2367398/what-is-the-ellipsis-for-in-this-method-signature –