What is the reason that a java method cannot return more than one value?
<p>As you know in python, a function can returns more than one value</p>

<p>eg:</p>

<pre><code>def myfun():
    return 1, 2, 3  
</code></pre>

<p>And we can call it in this way:</p>

<pre><code>a, b, c= myfun()
</code></pre>

<p>But in JAVA, we have cannot return more that one value, so we have to create one object containing the values that we want to return:</p>

<pre><code>class MyObject {

    private Integer a;
    private Integer b;
    private Integer c;

    public Integer getA() {
        return a;
    }
    public void setA(Integer a) {
        this.a = a;
    }
    public Integer getB() {
        return b;
    }
    public void setB(Integer b) {
        this.b = b;
    }
    public Integer getC() {
        return c;
    }
    public void setC(Integer c) {
        this.c = c;
    }
}
</code></pre>

<p>and our function will return this object</p>

<p>eg:</p>

<pre><code>public MyObject myfun(){
     MyObject myObject = new MyObject();
     myObject.setA(1);
     myObject.setB(2);
     myObject.setC(3);
     return myObject;
}
</code></pre>

<p>ÙAnd we call it in this way:</p>

<pre><code>obj = myfun();
Integer a = obj.getA();
Integer b = obj.getB();
Integer c = obj.getC();
</code></pre>

<p>Another solution is to return an array containing all the values that should be returned</p>

<p>But the both methods are ugly in coding, is there any limitation in JAVA so a method cannot returns more than one value?</p>

<p>Strictly speaking, Python does not return more than one value either. <code>1, 2, 3</code> is a tuple; it's just that Python's syntax supports automatically unpacking that tuple into separate variables.</p>

java python