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

    From sandeep6699@yahoo.com@21:1/5 to All on Wed Sep 14 09:21:45 2016
    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

    }

    }

    Since primitive types are passed by values, and primitive type wrapper classes are immutable, I am thinking of having outIntParam and outDoubleParam as instance variables in the class, which get set prior to calling myMethod. Then myMethod can make do
    with only one parameter i.e.

    class MyClass {
    protected int outIntParam;
    protected double outDoubleParam;

    int getOutIntParam() {
    return outIntParam;
    }

    double getOutDoubleParam() {
    return outDoubleParam;
    }
    //
    // And Settors for these instance variables
    // …

    int myMethod(int inIntParam) {
    // Accepts inIntParam as input
    // Updates instance variables in outIntParam and outDoubleParam
    // Returns an int

    }

    }

    Kindly suggest if there is a preferred way to realize the same.

    Regards,
    Sandeep

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)