Thursday, March 8, 2001 08:21 AM
I can think of two solutions.
First, use method overloading. Java allows you to use the same method name with different parameters. For instance, all of the following methods can be used in the same class:
int indexOf(int ch, int fromIndex)
int indexOf(String str)
int indexOf(String str, int fromIndex)
These three methods (from the String class) have the same name and return type, but use different, 'optional' parameters.
The second option is to pass an enumerate of general data types to the method, and have the method decide what needs to be done.
public String myMethod (String str, Vector v)
public String myMethod (String str, Object  objs)
Within that Vector or Object array, you could store hundreds of optional arguments.
Parsing these, in no particular order, won't be fun or pretty. Also, this really isn't good coding style, because an evil programmer could abuse this method, and possibly make things nasty for you. However, it is a hack that will work.