Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #35606
| From | Eric Sosman <esosman@comcast-dot-net.invalid> |
|---|---|
| Newsgroups | comp.lang.java.programmer |
| Subject | Re: Good pattern for realizing the out-param capability in Java? |
| Date | 2016-09-14 17:25 -0400 |
| Organization | A noiseless patient Spider |
| Message-ID | <nrcf7k$ed3$1@dont-email.me> (permalink) |
| References | <ec81f584-4e19-4f0b-ba29-924ef4e1a570@googlegroups.com> <8959892d-cd75-4680-b836-260a971f3366@googlegroups.com> |
On 9/14/2016 3:54 PM, Eric Douglas wrote:
> On Wednesday, September 14, 2016 at 12:17:37 PM UTC-4, sande...@yahoo.com wrote:
>> I want to solicit the opinion of the Java experts about realizing the out-param capability in Java. Suppose there is a method in a class where I would like to realize the following:
>>
>> class MyClass {
>> int myMethod(int inIntParam, int outIntParam, double outDoubleParam) {
>> // Accepts inIntParam as input
>> // Updates outIntParam and outDoubleParam
>> // Returns an int
>> …
>> }
>> …
>> }
>
> Methods don't normally need to pass out more than one value, so when they do I either create a custom object or pass out an array. What advantage would you get from creating a generic custom class to pass out 2 values?
I disagree with the premise: It is fairly common for a computation
to generate more than one result. On the other hand, I agree with the
approach: It is (I feel) better to return the multiple results in a
single instance of a "holder" class. java.awt.Shape's getBounds()
method returns its *four* outputs in a java.awt.Rectangle instance,
and there are many similar examples among the standard classes.
Occasionally, though, the "out-param" simply cannot be avoided.
The various sort() methods of java.util.Arrays, for example, would be
a good deal less attractive if they left their argument arrays
unmodified and instead returned brand-new arrays as method results ...
--
esosman@comcast-dot-net.invalid
The Tooth Fairy has gone high-tech, now pays in Bitecoin.
Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Good pattern for realizing the out-param capability in Java? sandeep6699@yahoo.com - 2016-09-14 09:17 -0700
Re: Good pattern for realizing the out-param capability in Java? Robert Klemme <shortcutter@googlemail.com> - 2016-09-14 18:43 +0200
Re: Good pattern for realizing the out-param capability in Java? Eric Sosman <esosman@comcast-dot-net.invalid> - 2016-09-14 12:55 -0400
Re: Good pattern for realizing the out-param capability in Java? j4n bur53 <janburse@fastmail.fm> - 2016-09-14 21:00 +0200
Re: Good pattern for realizing the out-param capability in Java? Eric Douglas <e.d.programmer@gmail.com> - 2016-09-14 12:54 -0700
Re: Good pattern for realizing the out-param capability in Java? Eric Sosman <esosman@comcast-dot-net.invalid> - 2016-09-14 17:25 -0400
Re: Good pattern for realizing the out-param capability in Java? j4n bur53 <janburse@fastmail.fm> - 2016-09-14 23:45 +0200
Re: Good pattern for realizing the out-param capability in Java? Lew <lewbloch@gmail.com> - 2016-09-14 16:29 -0700
csiph-web