If you mean "can I return one thing or another from a method?" like this:
then the answer is yes.
If you mean "Can I return two things from a method?" then the answer is also yes:
If you mean "can I call return twice to return two things?" then the answer is no. The reason is shown in the first example - return will 'exit' the method. [ March 08, 2005: Message edited by: Paul Sturrock ]
Another trick to use (and, yes people, feel free to tell me that this isn't a good design... ) is output parameters. In C, this is typically doen with pointers-to-pointers, but in Java, we don't have pointers. But we do have arrays.
As I say, this is generally not good programming practice. Usually, I use this as is only a temporary approach, and wind up refactoring the method call into two methods or returning a complex type down the road.
Piscis Babelis est parvus, flavus, et hiridicus, et est probabiliter insolitissima raritas in toto mundo.
Yes, using array types to store individual return values which must be picked off from the correct indices isn't good practice (unless it's an obvious one like coordinates or something). As Joel said, it's better to define a "complex" type that holds your values and exposes them in a more meaningful manner. Then, your API tells you what it's doing rather than requiring someone to read your documentation to figure out which index to use to get what value. Also, if you do ever need to add stuff to the return value, it's much easier, especially if you were to want to add something into the middle of the array.
James Carman, President<br />Carman Consulting, Inc.
Russ, using Serializable doesn't buy you anything in your example, you could simply use Object as return type.
Type cases (your if statements using instanceof) are a bad idea, though - they fly in the face of OO programming. It's much better to use polymorphic behaviour instead.
The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
A magnificient life is loaded with tough challenges. En garde tiny ad: