Groovy question

Close, but not quite. If openOffset is non-zero non-null, the comparison would be to openOffset, otherwise to 95. What you show is shorthand for this:

if (value >= (openOffset ? openOffset : 95)) {

Effectively it's treating openOffset ? as a Boolean value test, where 0 or null return false, and all other values return true. What is left of the colon is the true case and right is the false case.

Often code will fail with this because of not anticipating zero as a valid value. If one only wants 95 if openOffset is null, then that would have to be tested for explicitly, like this:

if (value >= (openOffset != null ? openOffset : 95)) {

or flipped around

if (value >= (openOffset == null ? 95 : openOffset)) {

5 Likes