[516] in java-interest

home help back first fref pref prev next nref lref last post

Re: Multiple return values

daemon@ATHENA.MIT.EDU (Peter Kessler)
Tue Jun 27 13:53:12 1995

Date: Tue, 27 Jun 1995 10:08:42 -0700
From: Peter.Kessler@Eng.Sun.COM (Peter Kessler)
To: java-interest@java.Eng.Sun.COM

    In the IDL-to-Java compiler I've written, I handle `out' and `inout' 
parameters (which are equivalent to multiple return values) by generating, 
for each user-defined IDL type, a Holder class with a public instance 
variable of the user-defined type (and for convenience, a constructor that 
takes an instance of the user-defined type).  
    Then `out' and `inout' parameters are mapped as instances of the Holder 
classes.  Before the call the caller has to initialize the Holder instance 
for an `inout' parameter, and the callee can change the value of the 
instance variable inside the Holder before returning for an `out' or 
`inout' parameter.  In the IDL support classes I've also defined Holders 
for all the IDL basic and built-in types.

    I think there was a `style' in some Java code to pass arrays of length 
1 in places where in other languages you would use pointer or reference 
parameters.  I thought that was confusing, and since I'm generating the 
Java code from IDL declarations, it's not much extra work to also generate 
the Holder classes.

    I tried a mapping in which I defined, in the style of the Mesa 
programming language, a `return record' class for each IDL operation that 
returned more than one result.  That seemed to work just as well as Holder 
classes.  The difference is in the perturbation in the client code when you 
change an operation from returning a single result (as the result of the 
mapped Java method) to returning multiple results (e.g. with `out' 
parameters, via a return record result).  With Holder classes you just add 
the new parameter as a Holder instance.  With return records you have to 
change the way you access the original result of the operation, which I 
thought was an unnecessary complication.

			... peter
-
Note to Sun employees: this is an EXTERNAL mailing list!
Info: send 'help' to java-interest-request@java.sun.com

home help back first fref pref prev next nref lref last post