1

Is there any way to add default condition into if else loop. If X is true then operation1 executes else operation2. If X is null then default operation gets executed.

if (x)
{ operation1 }
else
{ operation2 }
default
{default operation}
DummyGuy
  • 425
  • 1
  • 8
  • 20

1 Answers1

1

No default null-condition is provided in Java/Groovy as a null is not treated as default case.

You have to check against the null yourself:

if (null)
{ operationNull }
else if (x)
{ operation1 }
else
{ operation2 }
injecteer
  • 20,038
  • 4
  • 45
  • 89