Java method overload
<p>I have 2 alternatives to implement a calculation method, and I am wondering what would be the better approach.</p>

<p>The method needs some int and double parameters and (in some cases) a special flag to do some different calculation. </p>

<p>In the first example, I could call the method with 'calculateFoo(1, 2.0d)' to have the boolean flag == FALSE.</p>

<p>In the second example, I always have to set the boolean flag (even if I do not need it)</p>

<p>Method 1: (here I'm using the '...' as an 'method overloading' parameter)</p>

<pre><code>public SomeObject calculateFoo(int pIntValue, double pDoubleValue, boolean... pDoSpecialStuff) {

    if (pDoSpecialStuff.length == 0 || pDoSpecialStuff[0] == false) {
        // method was called without boolean flag or boolean flag was set to FALSE

        // do some calculation stuff
        // ...
    } else {
        // mehtod was called with boolean flag == TRUE

        // do some other calculation stuff
        // ...
    }

    return SomeObject; 
}
</code></pre>

<p>Method 2: (this is the 'common' approach)</p>

<pre><code>public SomeObject calculateFoo(int pIntValue, double pDoubleValue, boolean pDoSpecialStuff) {

    if (pDoSpecialStuff == false) {
        // mehtod was called with boolean flag == FALSE

        // do some calculation stuff
        // ...
    } else {
        // mehtod was called with boolean flag == TRUE

        // do some other calculation stuff
        // ...
    }

    return SomeObject; 
}
</code></pre>
