Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>A long time ago I had a conversation with Ken Arnold (one time member of the Java team), this would have been at the first Java One conference probably, so 1996. He said that they were thinking of adding multiple return values so you could write something like:</p> <pre><code>x, y = foo(); </code></pre> <p>The recommended way of doing it back then, and now, is to make a class that has multiple data members and return that instead.</p> <p>Based on that, and other comments made by people who worked on Java, I would say the intent is/was that you return an instance of a class rather than modify the arguments that were passed in.</p> <p>This is common practice (as is the desire by C programmers to modify the arguments... eventually they see the Java way of doing it usually. Just think of it as returning a struct. :-)</p> <p>(Edit based on the following comment)</p> <blockquote> <p>I am reading a file and generating two arrays, of type String and int from it, picking one element for both from each line. I want to return both of them to any function which calls it which a file to split this way.</p> </blockquote> <p>I think, if I am understanding you correctly, tht I would probably do soemthing like this:</p> <pre><code>// could go with the Pair idea from another post, but I personally don't like that way class Line { // would use appropriate names private final int intVal; private final String stringVal; public Line(final int iVal, final String sVal) { intVal = iVal; stringVal = sVal; } public int getIntVal() { return (intVal); } public String getStringVal() { return (stringVal); } // equals/hashCode/etc... as appropriate } </code></pre> <p>and then have your method like this:</p> <pre><code>public void foo(final File file, final List&lt;Line&gt; lines) { // add to the List. } </code></pre> <p>and then call it like this:</p> <pre><code>{ final List&lt;Line&gt; lines; lines = new ArrayList&lt;Line&gt;(); foo(file, lines); } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload