It is a short cut to if-else statement.
Syntax
value = (expression) ? statement1 : statement2
If the expression is evaluated to true, then statement1
is assigned to the value, else statement2 is assigned to the value.
HelloWorld.groovy
a = 10 message = (a == 10) ? "a is equal to 10" : "a is not equal to 10" println message
Output
a is equal to 10
No comments:
Post a Comment