Reason for the existence of non-short-circuit logical operators

后端 未结 6 1235
借酒劲吻你
借酒劲吻你 2020-11-28 08:16

When used with boolean operands, & and | become logical operators per Section 15.22.2 of the JLS. Unlike &&

6条回答
  •  无人及你
    2020-11-28 08:50

    In my case, I have two methods that compare two different but related objects (Object2 is an attribute of Object1) to see if there were any changes. An update needs to happen if either are updated, but both need to be evaluated so that the objects will be modified if both have been changed. Therefore, a single pipe "OR" comparison is required.

    EX:

    if (compare(object1, currentObject1) | comparison(object2, currentObject2)) {
        updateObject1(object1);
    }
    

提交回复
热议问题