0

The only thing i know is that (...) indicates that Texture key is an optional parameter for the method.Are there any other uses ?

Texture[] key;                              //1
public Animation( Texture ... key ) {       //2
    this.key = key;                         //3
}
KostasRim
  • 2,053
  • 1
  • 16
  • 32
  • possible duplicate of [When do you use varargs in Java?](http://stackoverflow.com/questions/766559/when-do-you-use-varargs-in-java) – reto Oct 30 '14 at 14:15

3 Answers3

3

Texture ... key does not denote optional parameters, but actually an unspecified number of arguments to a method. Java treats the variable-length argument list as an array.

More information on VarArgs

gtgaxiola
  • 9,241
  • 5
  • 42
  • 64
2
Texture ... key

This is used if you don't know how many parameters will be passed. key will be an array with the parameters that were passed to the Animation method. You can pass n number of parameters of type Texture.

brso05
  • 13,142
  • 2
  • 21
  • 40
2

... indicates a varargs parameters. It's basically an array that can be empty.

So

Animation();

is a valid call, as well as

Animation(key1, key2);

Note that only one varargs parameter is allowed per method and that it must be the last parameter of the method

ortis
  • 2,203
  • 2
  • 15
  • 18