a language feature of Sather that Java does not have. Java methods can accept
multiple inputs/parameters, but many return only a single value/output. However, Java
methods may return an object that has more than one field.
Here are some ways to fake returning
multiple values in Java.
Create a class with several fields. Return an object of this class. The problem
with this approach is you can have an explosion of tiny classes, each used by only
one method. It is considered bad form to create result classes of scattered fields
that are not logically related.
Rethink your methods so that there are a small number of possible result
classes that have physical meaning.
Return an array of doubles or an array of
Objects. The drawback is you lose typing and keyword
identification of results.
Create a class with a number of internal variables. To use it you call
setXXX to set each of the inputs, then call
calcXXX to calculate each of the possible calculations.
Then call getXXX to get each of the results. This is
the most Javaesque solution. Dozens of methods can share the same class.
Java’s GregorianCalendar works this way.
Have your method return a result and if there is a problem throw an
Exception, rather than returning a result and status as
you would in C.
The problem is made worse if you try to write C in Java, rather than thinking OO (Object Oriented).
See if you can rethink your interface so that your methods don’t return