Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #35606

Re: Good pattern for realizing the out-param capability in Java?

Path csiph.com!eternal-september.org!feeder.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
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 Wed, 14 Sep 2016 17:25:01 -0400
Organization A noiseless patient Spider
Lines 31
Message-ID <nrcf7k$ed3$1@dont-email.me> (permalink)
References <ec81f584-4e19-4f0b-ba29-924ef4e1a570@googlegroups.com> <8959892d-cd75-4680-b836-260a971f3366@googlegroups.com>
Mime-Version 1.0
Content-Type text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding 8bit
Injection-Date Wed, 14 Sep 2016 21:25:08 -0000 (UTC)
Injection-Info mx02.eternal-september.org; posting-host="3c2d73b4e7d1c9c00b5411ebb3357b4a"; logging-data="14755"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/CSU6LwisbiNX8F1lCl70m"
User-Agent Mozilla/5.0 (Windows NT 10.0; WOW64; rv:45.0) Gecko/20100101 Thunderbird/45.3.0
In-Reply-To <8959892d-cd75-4680-b836-260a971f3366@googlegroups.com>
Cancel-Lock sha1:o/cz+ZI2HgyyYtvcsxmEB+slVr8=
Xref csiph.com comp.lang.java.programmer:35606

Show key headers only | View raw


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


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