I recently discovered that Java (and Scala) include non-short-circuiting logical operators &
, |
, and ^
. I previously thought these only worked as bitwise operators. While maybe there is an argument for ^
, I can't think of very good reasons for using non-short-circuiting logical operators--although sure, I can contrive an example.
Are these operators useful? They seem more likely to cause hard-to-catch bugs.
scala> def foo = {
| println("foo")
| true
| }
foo: Boolean
scala> def bar = {
| println("bar")
| true
| }
bar: Boolean
scala> foo || bar
foo
res5: Boolean = true
scala> foo | bar
foo
bar
res6: Boolean = true