Varrgs
As with generics, the beam parameter is a language characteristic in C and Java. In the past, if we want to pass a variable number of functions to a function, you must first put these parameters in an array, then Pass the array to a function. Just as the same below:
Object [] arguments = {640, "kb", "anybody", "bill gates"}; string result = messageformat.format ("{3}: {0, Number, integer} {1} OUGHT To Be ENOUGH for { 2} ", arguments);
In J2SE 5.0, the parameters are still being sent into the corresponding method, but different, you no longer need to manually create arrays, but only need to list those parameters, other work by virtual Mechanic you finished. So now we can write this:
String result = messageformat.format ("{3}: {0, Number, Integer} {1} OUGHT TO BE ENOUGH for {2}", 640, "KB", "Anybody", "Bill Gates");
We use an example function to illustrate the definition of the variable length parameter function. This function prints a few dogs of a person.
Private void printdognames (String ... Dogs) {system.out.println ("i Have" Dogs.length "DOGS:"); for (String Dogname: Dogs) {system.out.println (Dogname); }
In fact, the long parameter DOGS is an array.
A function of a function can only have a long parameter, so it is illegal similar to the following definition:
Private void PrintDognames (String ... Dogs, Float ... dogage)
If you decide to set the function parameter to a variable length, you must think of the situation, that is, the program that is called is likely to give you any parameters. At this time, the array of parameters is 0, and this is in grammar It is completely legal, so you must take into account this in the function definition.