Return different type of data from a method in java?

前端 未结 13 1498
别那么骄傲
别那么骄傲 2020-12-05 02:18
public static void main(String args[]) {
    myMethod(); // i am calling static method from main()
 }

.

public static ? myMethod(){         


        
13条回答
  •  再見小時候
    2020-12-05 02:59

    Finally i thought my way is better since when number of return types go higher this kind of a implementation do that in best way.

    public static ReturningValues myMethod() {
    ReturningValues rv = new ReturningValues();
    rv.setValue("value");
    rv.setIndex(12);
    return rv;
    }
    

提交回复
热议问题