What are these three dots in parameter types [duplicate]
Possible Duplicate:
What is the ellipsis for in this method signature开发者_开发问答?
For example: protected void onProgressUpdate(Context... values)
One word: varargs
.
The three periods after the final parameter's type indicate that the final argument may be passed as an array or as a sequence of arguments. Varargs can be used only in the final argument position.
They're called varargs, and were introduced in Java 5. Read http://download.oracle.com/javase/1.5.0/docs/guide/language/varargs.html for more information.
In short, it allows passing an array to a method without having to create one, as if the method took a variable number of arguments. In your example, the following four calls would be valid :
onProgressUpdate();
onProgressUpdate(context1);
onProgressUpdate(context1, context2, context3);
onProgressUpdate(new Context[] {context1, context2});
Its the varargs
introduced in java 5. more info at Varargs
Three dots are called ellipsis. Method can be called any number of values of type Context. You can call that method with no value also.
It means that the values
argument is an optional array of Context
objects. So you could call the "onProgressUpdate" function in the following ways:
onProgressUpdate(); // values is an empty array.
onProgressUpdate(new Context[] { new Context() }); // values has one item.
onProgressUpdate(context1, context2); // values has two items.
See the varargs language feature introduced in Java 1.5.
That means that you can put a range of values :
onProgessUpdate(c1,c2,c3);
精彩评论