Possible Duplicate:
What is the ellipsis for in this method signature?
For example: protected void onProgressUpdate(Context... values)
(three dots in JavaScript) is called the Spread Syntax or Spread Operator. This allows an iterable such as an array expression or string to be expanded or an object expression to be expanded wherever placed.
The three dots (…) notation referred to as the Spread syntax has been part of React for a long time when it could be used via transpilation, although, it has been made a part of JavaScript as part of the ES2015 syntax.
The three dots are known as the spread operator from Typescript (also from ES7). The spread operator return all elements of an array. Like you would write each element separately: let myArr = [1, 2, 3]; return [1, 2, 3]; //is the same as: return [...myArr];
When we see three dots (…) in the code, it's either rest parameters or the spread operator. There's an easy way to distinguish between them: When three dots (…) is at the end of function parameters, it's "rest parameters" and gathers the rest of the list of arguments into an array.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With