[1862] in java-interest
Re: functions with multiple OUT parameters...
daemon@ATHENA.MIT.EDU (Chuck McManis)
Mon Sep 18 21:34:53 1995
Date: Mon, 18 Sep 1995 14:47:15 -0700
From: cmcmanis@scndprsn.Eng.Sun.COM (Chuck McManis)
To: java-interest@java.Eng.Sun.COM, caveh@mufasa40.Eng.Sun.COM
>is there preferred way to return more than one object from a function?
No, however this is on the list for investigation at a future time.
You can work around it in one of several ways:
For your example...
void MyGettimeofday(MyDate date, MyZone zone);
Assumption MyDate and MyZone are both classes.
WA#1 (Work Around #1)
Purpose built class:
class GetTimeOfDayResult {
public MyData date;
public MyZone zone;
}
GetTimeOfDayResult MyGettimeofday(MyDate date, MyZone zone);
Here you have a class which consists of both results you wish
to return.
WA#2
Array of objects
Object [] MyGettimeofday(MyDate date, MyZone zone);
Object res[] = MyGettimeofday(MyDate date, MyZone zone);
date = (MyDate)(res[0]);
zone = (MyZone)(res[1]);
WA#3
Use statics for temporary results.
class foo {
public static MyDate dateRes;
public static MyZone zoneRes;
void MyGettimeofday(MyDate date, MyZone zone);
}
foo.MyGettimeofday(MyData date, MyZone zone);
date = foo.dateRes;
zone = foo.zoneRes;
Variations on these themes are also possible. Note I don't propose any
one over the other, nor do I claim they should get any style points,
simply they will accomplish what you seek to achieve.
--Chuck
-
Note to Sun employees: this is an EXTERNAL mailing list!
Info: send 'help' to java-interest-request@java.sun.com