【问题标题】:If-else and default condition in groovy scriptgroovy 脚本中的 if-else 和默认条件
【发布时间】:2021-12-05 10:36:01
【问题描述】:

有没有办法将默认条件添加到 if else 循环中。如果 X 为真,则 operation1 执行 else operation2。如果 X 为 null,则执行默认操作。

if (x)
{ operation1 }
else
{ operation2 }
default
{default operation}

【问题讨论】:

  • if(x) {...} else if (x!=null) {...} else {...}

标签: if-statement groovy


【解决方案1】:

在 Java/Groovy 中没有提供默认的 null 条件,因为 null 不被视为默认情况。

您必须自己检查null

if (null)
{ operationNull }
else if (x)
{ operation1 }
else
{ operation2 }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-07-25
    • 1970-01-01
    • 2021-01-13
    • 1970-01-01
    相关资源
    最近更新 更多