Does the compiler continue evaluating an expression where all must be true if the first is false?

后端 未结 6 1929
误落风尘
误落风尘 2020-12-11 21:41

I\'m sure this question has probably been answered before, so I apologize, but I wasn\'t able to find the proper search terms to find the answer.

Given the following

6条回答
  •  离开以前
    2020-12-11 22:00

    It is shortcircuiting and allows you to do things like this:

    if(ob && ob.somefunc()) { ... }
    

    if both operations were evaluated, there would be a possibility of referencing a null object, which would be a runtime exception.

提交回复
热议问题