简体   繁体   English

从两个不同的类调用相同的方法

[英]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 . 对于第一个类,该方法正在执行, returnFlag = true While for other, even with the same parameters, it is returning false. 而对于其他参数,即使具有相同的参数,也会返回false。

Be assured that because the code in the try block does not ever throw an exception, your function is equivalent to 请放心,由于try块中的代码不会引发异常,因此您的函数等效于

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. 如果xy实际上是Integer类型,则==可能由于引用比较而失败,或者在调用函数时将null Integer自动拆箱为int时抛出NPE。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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