简体   繁体   中英

Calling same method from two different class

public boolean createPricebreakupOrder(int x, int y) {
    boolean returnFlag = false;

    try {
        if (x == y) {
            returnFlag = true;
        }
    } catch (final Exception e) {
        LOG.debug("Exception while Price Breakup Create" + e.getMessage());

        returnFlag = false;
    }

    return returnFlag;
}

Now I am calling this method from two different classes; and passing the same parameter in, from each class. For the first class, the method is getting executed and returnFlag = true . While for other, even with the same parameters, it is returning false.

Be assured that because the code in the try block does not ever throw an exception, your function is equivalent to

public boolean createPricebreakupOrder(int x, int y)
{
    return x == y;
}

There is nothing non-deterministic about this function: the same input parameters will yield the same result.

If x and y were actually Integer types then it's possible that == will fail due to reference comparisons or, perhaps, an NPE is thrown when auto-unboxing a null Integer to an int when the function is called.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM