×

Loading...
Ad by
  • 予人玫瑰,手有余香:加拿大新天地工作移民诚聘求职顾问&行业导师!
Ad by
  • 予人玫瑰,手有余香:加拿大新天地工作移民诚聘求职顾问&行业导师!

请问:在JAVA中

调用METHOD可有几个参数IN,但用RETURN只能得到一个OUT参数.
例如: private String myMethod( int inValue1, double inValue2 )
{
String outValue;
.....
return outValue;
}
请问:除了
1:在类中定义一个全局变量,从而在myMethod中给这个全局变量赋值
2: 定义成多个METHOD,
如: myClass.getOutValue1( int inValue1, double inValue2 ),
myClass.getOutValue2( int inValue1, double inValue2 )
外,还有什么更聪明点的方法吗?谢先
Report

Replies, comments and Discussions:

  • 工作学习 / IT技术讨论 / 请问:在JAVA中
    调用METHOD可有几个参数IN,但用RETURN只能得到一个OUT参数.
    例如: private String myMethod( int inValue1, double inValue2 )
    {
    String outValue;
    .....
    return outValue;
    }
    请问:除了
    1:在类中定义一个全局变量,从而在myMethod中给这个全局变量赋值
    2: 定义成多个METHOD,
    如: myClass.getOutValue1( int inValue1, double inValue2 ),
    myClass.getOutValue2( int inValue1, double inValue2 )
    外,还有什么更聪明点的方法吗?谢先
    • value class
      • 不太明白,能解释下吗?
        • I guess: make the method return a class object, and then call the getValue methods of that object to get all return values.
          • right, define a inner class to do this job.
    • 不动脑子的解决办法,把所有返回值放在Vector里面传回去就行乐。
      • 对于返回参数是同类型的可以,但如果既有String,又有double,还有boolean怎么办呢?
        • 谁说只能是同一类型,Vector可什么都能装
          • Thank you,I will try it
    • 太多方法了,你可以放在 array, vector, list or class 里面....
      • Thank you,I will try
    • 谢谢,因为JAVA的速度差强人意,所以有时不只考虑实现的方法,还要选个性能好,不浪费资源的.测试中....
    • encapsulate primitive type arguments
      If you want to change the values of arguments, you can encapsulate primitive type arguments with related classes. For example:

      void myMethod(Integer v1, Double v2) {
      //modify the fields of v1, v2
      ...}

      callerMethod() {
      int a = 5;
      double b = 2.3;
      Integer v1 = new Integer(a);
      Double v2 = new Double(b);
      myMethod(v1, v2);
      a = v1.intValue();
      b = v2.doubleValue();
      }