Hi Ted,
The '||' operator is a 'short circuit' operator, and it evaluates the left-hand
side first. Assume this.dueDateType() returns null, then in this case:
On 31/07/2010, at 9:35 PM, Theodore Petrosky wrote:
> if (this.dueDateType() == null || this.dueDateType().equals("N")) {
the expression on the left-hand side is true, and the right-hand side is never
evaluated (because its value won't affect the value of the whole expression).
That is, it "short circuits" and you avoid a NullPointerException. In this
case:
> if (this.dueDateType().equals("N") || this.dueDateType() == null) {
this.dueDateType().equals("N") is evaluated, and you get a NullPointerException.
> I don't really care that I must check in a specific order... It just took me
> time to understand that the order was important.
The order is only important to the extent that the LHS is always evaluated, and
the RHS is only evaluated if the LHS is false. So in this case, where you're
doing a null check specifically to avoid an exception, yes it needs to be on
the LHS.
http://en.wikipedia.org/wiki/Short-circuit_evaluation
--
Paul.
http://logicsquad.net/
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list ([email protected])
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/webobjects-dev/archive%40mail-archive.com
This email sent to [email protected]