Re: How can I create a method which takes one or more...
Posted By:
Michael_Rohde
Posted On:
Saturday, February 3, 2001 10:13 AM
You have to create an extra method for each combination ("signature") of parameters desired. But the methods can, of course, rely on each other:
void createCircle(int x, int y, int radius) {
// do something
}
void createCircle(int x, int y) {
createCircle(x, y, 100);
}
Re: How can I create a method which takes one or more...
Posted By:
Nicholas_Whitehead
Posted On:
Tuesday, January 30, 2001 02:27 PM
Something along the lines of:
public void optArgFunction(Object[] optArgs) {
.
.
.
.
}
Simple, but it works.
Re: How can I create a method which takes one or more...
Posted By:
Chandra_Patni
Posted On:
Tuesday, January 30, 2001 02:28 AM
In Java there is no construct like ... operator in C where you can pass optional parameters. You can, however, achieve the same effect by overloading a method.
Re: How can I create a method which takes one or more...
Posted By:
Pratik_Roy
Posted On:
Tuesday, January 23, 2001 11:05 AM
You will have to create multiple methods with different signatures, having same method name. Java supports Function overloading. So you can write the functions (methods) with various parameters (or no parameter), and they would be called automatically, based on the no. of parameters, type of parameters, and order of the parameters. This is usually known as the "signature" of the function. And there is no limitation on the different signatures that can be created for a method (function).